Passing post_id for comment through comments controller
I have two models with a belongs_to/has_many relati开发者_如何学Goonship. 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 %>
You can pass a params from view to a controller method but I don't think you can pass a params to a controller then to a view.
In your new action, you may have to declare a @variable and define it to be your params where you can use it in your view.
But, you have already have @post.id, why can't you just use that?
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论