How do I add to a model when on the Show of another model?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-04-22T20:28:43Z Indexed on 2010/04/22 20:33 UTC
Read the original article Hit count: 229

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about forms

Related posts about formtastic