# Form for 2 models?

**URL:** <https://www.ruby-forum.com/t/form-for-2-models/143377>\
**Category:** Rails\
**Created:** [July 17, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/form-for-2-models/143377 "2008-07-17T20:43:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 17, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/form-for-2-models/143377/1 "2008-07-17T20:43:53Z")

</div>

Is it possible to have a form\_for :model\_1, :model\_2 ?

Thanks

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 17, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/form-for-2-models/143377/2 "2008-07-17T21:13:28Z")

</div>

Ok, I figured out how to do it, but now I’m having soe trouble.

I want to be able to add model\_2’s to model\_1, when model\_1 already  
exists

def save\_model\_1  
current\_model\_1 = Model\_1.find(params[:model\_1])

```
if current_model_1
  @model_2 = current_model_1.model_2s.build(params[:model_2])
else
  @model_1 = Model_1.new(params[:model_1])
  @model_2 = current_model_1.model_2s.build(params[:model_2])
end

if current_model_1
    render :action => 'index'
else
  if @model_1.save
    render :action => 'index'
  else
    render :action => 'new_model_1'
  end
end

```

end

I get this error:

ArgumentError in Auth userController#save\_model\_1  
Unknown key(s): title

In new\_model\_1.html.erb:  
\<%= text\_field :model\_1, :title %\>

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 17, 2008, 10:09pm UTC](https://www.ruby-forum.com/t/form-for-2-models/143377/3 "2008-07-17T22:09:19Z")

</div>

> Is it possible to have a form\_for :model\_1, :model\_2 ?

No, but you can have fields\_for.
