Answer the question
In order to leave comments, you need to log in
How and what parameters should be passed to the form if the route is nested?
Good evening.
There is a user, a comment model has been added to the user, all associations are spelled out correctly, the route is nested (comments are nested in the jureza).
When creating a form - writes the method does not exist.
I write like this:
<%= form_for ([@user, @user.comments.build]) do |f| %>
<%= f.label :body %>
<%= f.text_field :body %>
<%= f.text_field :user_id %>
<%= f.submit' %>
<% end %>
@user = User.find(params[:user_id])
@comment = @user.comments.create(send_params)
Answer the question
In order to leave comments, you need to log in
What mistake? What's in the new comment controller? How defined routes? Why does the submit button have an extra quote in the form? )<%= f.submit' %>
Can be in the form to specify simply the user and object of the comment?
Because in the controller you still create it directly through the user.
Well, this is just a guess, I myself don’t shine with experience yet, but on such questions, additional experience is filled just right.
And what for in the form this field?
If to get the user in the controller, then he will come in the same way in the parameters. <%= f.text_field :user_id %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question