views:

29

answers:

1

Say you have a Post model that has a :title, :author, :content, etc. It also has a :thread_id attribute, and it belongs_to :thread.

The thread model doesn't have any custom fields. The only ones you'll be needing are those created by default such as :id, :created_at, and :updated_at. Threads have_many :posts.

How do you create a form for a Thread that simultaneously creates both a Thread and a Post?


Related questions, possibly:

  • Should I say <% form_for @new_thread ... %> or <% form_for @new_post ... %>?
  • Should the form be in the Thread view code or the Post view code?

Thanks for your help, I am new to Rails and I'm still learning how to organize my code in it.

+2  A: 

check out

http://railscasts.com/episodes/196-nested-model-form-part-1

and the accepts_nested_attributes_for method.

Doon