Answer the question
In order to leave comments, you need to log in
How to implement routing and communication between models?
Question from a completely newbie.
Actually, there is an implemented User model with an input and output.
Task: to give each such User the opportunity to create an event (Event model) and, in fact, display on Ch. page at User.
The connection itself seems to be clear: User has many :events, Events belongs_to :user
But what about routing?
That is, it is necessary that the user's page has a button "Create new event", and when the transition is redirected to <>/user/id1/create_event
Answer the question
In order to leave comments, you need to log in
/user/id1/create_event is not the Rails way. In rails, everything is already invented for you:
resources :users do
resources :events
end
@user = User.find(params[:id]])
@event = @user.events.find(params[:event_id])
Something like this
resources :user do
member do
get :create_event
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question