Ruby on rails 新手,我以前一直在使用 CakePHP,希望允许我的创建评论控制器为两个模型创建事件,有什么帮助吗?
我的评论控制器:
def create
@event = Event.find(params[:event_id])
@comment = @event.comments.create(params[:comment].permit(:commenter, :body))
redirect_to event_path(@event)
end
def create
@venue = Venue.find(params[:venue_id])
@comment = @venue.comments.create(params[:comment].permit(:commenter, :body))
redirect_to venue_path(@venue)
end
我的创建评论视图:
<h2>Add a comment:</h2>
<%= form_for([@event, @event.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 %>