# Create subform within rails form

**URL:** <https://www.ruby-forum.com/t/create-subform-within-rails-form/180972>\
**Category:** Rails\
**Created:** [January 2, 2010, 1:45pm UTC](https://www.ruby-forum.com/t/create-subform-within-rails-form/180972 "2010-01-02T13:45:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amabdelsalam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@amabdelsalam](https://www.ruby-forum.com/u/amabdelsalam)\
**Post date:** [January 2, 2010, 1:45pm UTC](https://www.ruby-forum.com/t/create-subform-within-rails-form/180972/1 "2010-01-02T13:45:29Z")

</div>

Hi,

I have a form for a model that have relationship to other models in my  
application. For example, a company and employees. When I add new  
employee, I should select company for which employee is working. How  
about if the employee works in a company that is not in my database? so  
I want to create that company within the same form of adding employee  
(sub form). Can anyone tell me how to do that in rails?

Ahmed

---

<div class="post-metadata">

**Author:** ![amabdelsalam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@amabdelsalam](https://www.ruby-forum.com/u/amabdelsalam)\
**Post date:** [January 2, 2010, 1:50pm UTC](https://www.ruby-forum.com/t/create-subform-within-rails-form/180972/2 "2010-01-02T13:50:57Z")

</div>

Hi,

I am doing just that in my application.

First I would like to give you a heads up that HTML does not work well  
with  
nested FORMS, at least the browsers do not. So you will have to ensure  
that  
the forms aren’t nested, you can still make them appear nested /  
subforms by  
using relative positioning however.

Second in my scenario I felt best to have AJAX forms for the creation  
purpose so that I can create the object without having to leave the main  
form, you should consider something similar.

Beyond that it depends on your exact scenario that you wish to create.

Thanks & Regards,  
Dhruva S…

On Sat, Jan 2, 2010 at 6:15 PM, Ahmed A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> –  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![amabdelsalam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@amabdelsalam](https://www.ruby-forum.com/u/amabdelsalam)\
**Post date:** [January 2, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/create-subform-within-rails-form/180972/3 "2010-01-02T15:22:15Z")

</div>

On Sat, Jan 2, 2010 at 4:45 AM, Ahmed A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> 

Ahmed, it seems that you’re needing a multi model form that accepts  
nested  
attributes. Thus,  
you might want to take a look at the following example:

> **[Nested Model Forms](https://rubyonrails.org/2009/1/26/nested-model-forms)**
>
> The most popular request on our new Feedback site was for the ability to easily manage multiple models in a single form. Thankfully Eloy Duran has a patch that does just this. But before we roll it into rails 2.3 we want to get some more feedback...

Good luck,

-Conrad

> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
