It's pretty easy, but switching between frameworks / languages makes me doubtful. Trying to work out routes for has_many :through relationships in Rails.
#User has_many :reservations, :dependent => :destroy has_many :events, :through => :reservations
I need routes where from the user model I can quickly create / create a new reservation for a specific event (& vice versa), but I don’t know how to do it. It looks weird:
resources :users do resources :reservations, only: [:new, :create, :destroy] end resources :events do resources :reservations, only: [:new, :create, :destroy] end
In any case, just looking for confirmation, or perhaps an alternative way to deal with it. Ideally, there is a link on the page next to the event that the user could click and (either through ajax or reload the page), they would make a “reservation”.
Similarly, I need a route to see every user who has a reservation for this event. And every event for which this user is reserved.
source share