This is pretty easy but switching back n' forth between frameworks/languages has me doubting myself. Trying to work out routes for has_many :through
relationship in Rails.
#User
has_many :reservations, :dependent => :destroy
has_many :events, :through => :reservations
#Reservation
belongs_to :user
belongs_to :event
#Event
has_many :reservations, :dependent => :destroy
has_many :attendees, through => :reservations, :source => :user
I want routes where from a User model I can quickly build/create a new reservation to a specific Event (& vice versa) but not sure how to go about creating them. This looks odd:
resources :users do
resources :reservations, only: [:new, :create, :destroy]
end
resources :events do
resources :reservations, only: [:new, :create, :destroy]
end
Anyway, just looking for verification, or perhaps an alternative way to handle this. Ideally there's a link on a page next to event that a user could click and (either through ajax or page reload) they would have made a 'reservation'.
By the same token I need route to see every user who has a reservation to an given event. And every event that a given user is reserved for.