> On Feb 15, 2016, at 12:28 PM, Szabolcs Toth <li...@ruby-forum.com> wrote:
> 
> I have completely lost with this simple problem. I have two model, Post
> and Comment. I added the one-to_many associations. When I want to add a
> comment to a certain post I use this:
> 
> <%= link_to 'Add comment', new_comment_path(id: post.id) %>
> 
> In the comments_controller.rb I have
> def create
>    @comment = Comment.new(comment_params)
>    @comment.post_id = params[:id]
> 
> But it doesn't work, what did I miss? Thank you!
> 

If you're sending this to the comments controller, then set the post_id 
attribute in that form. id always refers to the object of the form (in this 
case the comment) rather than the parent.

Walter

> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/b8675d6aca1ce38b6be0059004caf2b8%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/7342C104-B562-4A6B-850C-0CFCBDFB957C%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to