0
Hello, I have the following problem:
I am creating a film rental system at a college job where the user can rent movies from different rental companies.
The first problem I’m having with routes, is that a user can add movies to favorites, so I tried to create the route this way:
  resources :usuarios do
    resources :filmes
  end
that generated the routes:
    usuario_filmes GET    /usuarios/:usuario_id/filmes(.:format)      filmes#index
           POST   /usuarios/:usuario_id/filmes(.:format)      filmes#create
new_usuario_filme  GET    /usuarios/:usuario_id/filmes/new(.:format)  filmes#new
edit_usuario_filme GET    /usuarios/:usuario_id/filmes/:id/edit(.:format)      filmes#edit
    usuario_filme  GET    /usuarios/:usuario_id/filmes/:id(.:format)  filmes#show
           PATCH  /usuarios/:usuario_id/filmes/:id(.:format)  filmes#update
           PUT    /usuarios/:usuario_id/filmes/:id(.:format)  filmes#update
               DELETE /usuarios/:usuario_id/filmes/:id(.:format)  filmes#destroy
The problem is that these routes are calling the same actions that I use to create a new movie. My question is how to specify the actions to be called within the controller.
Another problem I’m having is with the table preco which refers to the lease value and the key of that table is composed of: locadora_id and filme_id. How do I create routes to register a new price? I’m trying it this way:
  match 'precos/new/:filme_id', controller: 'precos', action: 'new', via: 'get'
Where, in the view, the user informs the location id. But this route always calls the show method and understands that the new is the locator_id parameter, because the show method is defined like this:
precos/:locadora_id/:filme_id
I would love to be helped to better understand how the routes in Rails work.
The models:
class Preco < ApplicationRecord
    belongs_to :filme
    belongs_to :locadora
end
class Filme < ApplicationRecord
    has_and_belongs_to_many :usuarios
    has_many :precos, dependent: :destroy
end
class Locadora < ApplicationRecord
    has_and_belongs_to_many :usuarios
    has_many :precos, dependent: :destroy
end
I edited your answer, removing your email, if the author of the question has more questions, you should resolve them here or open a new question. Remember that his doubt may be of others so it is better for the community that the solution is always visible.
– Caique Romero
Obg Caique! I’ll remember that later...
– Anderson De Camargo