有谁知道如何将以下评论表格指向我的评论控制器中的hello操作,任何建议都将不胜感激:
<h2>Add a comment:</h2>
<%= form_for([@venue, @venue.comments.build]) do |f| %>
<p>
<%= f.label :commenter %><br />
<%= f.text_field :commenter %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
//////////////////我的评论员:
def hello
@venue = Venue.find(params[:venue_id])
@comment = @venue.comments.create(params[:comment].permit(:commenter, :body))
redirect_to venue_path(@venue)
end
答案 0 :(得分:1)
您必须正确设置路线,例如:
resources :venues do
resources :comments do
collection do
post :hello
end
end
end
并将表单网址设置为此操作的网址:
<%= form_for(@venue.comments.build, url: hello_venue_comments_path(@venue)) do |f| %>