Hello, I have the following problem:
I'm creating a movie rental system in 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 do you specify the actions that should be called within controller .
Another problem I'm having is with the preco
table that refers to the lease value and the key of that table is composed: locadora_id
and filme_id
. How do I create routes to register a new price? I'm trying this way:
match 'precos/new/:filme_id', controller: 'precos', action: 'new', via: 'get'
Where, in the view, the user informs the id of the store. But this route always calls the show method and understands that new is the locale_id parameter, because the show method is defined like this:
precos/:locadora_id/:filme_id
I would love to have you help me better understand how 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