If you just want to hide the field use: <%= f.hidden_field :post_id, value: params[:id] %>
See - http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-hidden_field On Tuesday, February 16, 2016 at 4:48:17 AM UTC-8, Ruby-Forum.com User wrote: > > Walter Davis wrote in post #1181415: > >> @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 > > Thanks, last night I tried this in the _form partial: > <%= f.text_field :post_id, value: params[:id] %> > > This way it is work, but I wouldn't like to show this to user, I'd like > to do it automatically. How can I do that? > > -- > 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/2e77997a-b5c2-47d1-82e6-f78ea87949fc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.