Answer the question
In order to leave comments, you need to log in
How to pass an object to a controller action?
There is a post controller and a comment controller.
Each post has a lot of comments, respectively.
In the index view of the post controller, along with each post, there is a form for adding a comment to a specific post.
I made a helper that generates an empty comment object (post.comments.build) to pass it to the form.
But how can I make it so that in the create action of the comment controller I create comments on a specific post?
After all, we cannot search for a post by id, for example, like this: post = Post.find_by(id: params[:id]) , because no id is actually transferred anywhere.
Thanks
Answer the question
In order to leave comments, you need to log in
You made a crutch with hidden field
What would be normal, you need to look at what nested resources routing is
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question