I have two models with a belongs_to/has_many relationship. Posts have many comments, comments belong to posts.
I need to pass the post_id through comments_controller.rb#new.
def new
@post = Post.find(params[:post_id])
@comment = Comment.new(:parent_id => params[:parent_id], :post_id => params[:post_id])
end
comment form:
<%= simple_form_for([@post, @post.comments.new]) do |f| %>
<%= f.input :post_id, :required => false, :as => :hidden %>
<%= f.input :parent_id, :required => false, :as => :hidden %>
<%= f.input :name, :label => false, :placeholder => "Name (optional)", :required => false %>
<%= f.input :content, :label => false, :placeholder => "Reply", :as => :text %>
<%= f.button :submit, "Reply" %>
<% end %>
@comment = @post.comments.build(:parent_id => params[:parent_id]). - sscirrus