How do I add to a model when on the Show of another model?
- by Angela
I on the Show of "Contacts" and want, from that page, to submit a Comment that is related to the Contact.
The way I understand to do it would be:
<%= start_form_tag :action => "add_comment", :id => @contact %>
<% text_area "comment, "body", "rows" = > 5 %> <br>
<%= submit_tag %>
<%= end_form_tag %>
I would create a method in the Contacts controller:
def add_comment
Contact.find(params[:id]).comments.create(params[:comment])
end
However, I feel there's a better way, but don't know what that is? I learned this on a pretty outdated book.
Basically, I want to add a new object belonging to a Model while on the Show of a different Model.
Would formtastic help me, and if so, how?