# Form\_for and Multiple Models Being Saved

**URL:** <https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841>\
**Category:** Rails\
**Created:** [September 24, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841 "2006-09-24T23:44:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 24, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/1 "2006-09-24T23:44:43Z")

</div>

Howdy Folks,

I want to use form\_for to allow a user to submit a form that contains  
two  
instances of the same model. They are entering calendar dates and I want  
them to be able to submit 2 from the same form.

Ok, so, using form\_for, what is the best way to do this? form\_for seems  
to  
be setup to handle a single instance in that it wants a name for the  
variable, etc…

Has someone else done this? Any quick pointers?

Beyond that, a related question. Some of these helpers support the  
:index  
option which I believe is designed to differentiate between multiple  
items  
of the same type in a form.

Something like this:

\<%= form.text\_field :event\_city, :index =\> @event\_date.id %\>

But, for an unsaved item, @event\_date.id will be nil so what do folks  
use to  
handle this?

Any help very much appreciated.

Cheers,  
Hunter

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 25, 2006, 12:34am UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/2 "2006-09-25T00:34:47Z")

</div>

On 9/24/06, HH [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to use form\_for to allow a user to submit a form that contains two  
> instances of the same model. They are entering calendar dates and I want  
> them to be able to submit 2 from the same form.
> 
> Ok, so, using form\_for, what is the best way to do this? form\_for seems to  
> be setup to handle a single instance in that it wants a name for the  
> variable, etc…
> 
> Has someone else done this? Any quick pointers?

Take a look at fields\_for. Use it within a form (whether form\_for or  
form\_tag).

Beyond that, a related question. Some of these helpers support the  
:index

> option which I believe is designed to differentiate between multiple items  
> of the same type in a form.
> 
> Something like this:
> 
> \<%= form.text\_field :event\_city, :index =\> @event\_date.id %\>
> 
> But, for an unsaved item, @event\_date.id will be nil so what do folks use  
> to  
> handle this?

You’d pass :index if you had multiple event\_city for a single record.  
Sounds  
like you don’t need it at all.

jeremy

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 8:45am UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/3 "2006-09-28T08:45:12Z")

</div>

I have a very weird problem where no one can connect to my server  
(“[foo.com](http://foo.com)”), even though DNS is working.

I’m running my rails app on port 8000 using this command:

# ./script/server webrick --port=8000 --environment=production

=\> Booting WEBrick…  
=\> Rails application started on [http://0.0.0.0:8000](http://0.0.0.0:8000)  
=\> Ctrl-C to shutdown server; call with --help for options  
[2006-09-27 23:06:42] INFO WEBrick 1.3.1  
[2006-09-27 23:06:42] INFO ruby 1.8.4 (2005-12-24) [i386-linux]  
[2006-09-27 23:06:42] INFO WEBrick::HTTPServer#start: pid=1345  
port=8000

When someone tries to access [http://foo.com:8000](http://foo.com:8000) from a remote  
location, their browser refuses to connect. I’ve tried it myself  
using lynx and wget and see these errors:

lynx says: “Alert! Unable to connect to remote host.”  
wget says: “connect: No route to host”

If I telnet to [foo.com](http://foo.com) on port 8000, telnet says:  
“telnet: Unable to connect to remote host: No route to host”

However, I can ping [foo.com](http://foo.com) successfully, and nslookup resolves it  
successfully too. If I re-run webrick on port 3000 (the default)  
everything works fine.

Anyone know why I can’t choose a nonstandard port for my rails server  
to run on? This is really stumping me. Any tips would be very  
appreciated!

Thanks everyone,  
-Jason

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/4 "2006-09-28T20:43:20Z")

</div>

You were right Vish. We needed to open port 8000 in iptables. Works  
fine now.

Thanks!  
-Jason

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/5 "2006-09-28T20:43:21Z")

</div>

I want “rake migrate” to act on my production db, not the development  
one; do I just change database.yml from this:

development:  
database: myproject\_development

…to this?

development:  
database: myproject\_production

Thanks!

-Jason

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 9:23am UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/6 "2006-09-28T09:23:16Z")

</div>

This might be blocked by your firewall.

Vish

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 9:13pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/7 "2006-09-28T21:13:26Z")

</div>

Hello Jason !

2006/9/28, Jason F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I want “rake migrate” to act on my production db, not the development  
> one; do I just change database.yml from this:

rake RAILS\_ENV=production db:migrate

## Hope that helps !

FranÃ§ois Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/8 "2006-09-28T21:33:32Z")

</div>

That did it… thanks JDL and Francois!

-Jason

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [September 28, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/form-for-and-multiple-models-being-saved/69841/9 "2006-09-28T21:15:27Z")

</div>

On 9/28/06, Jason F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> development:  
> database: myproject\_production

No. Leave your database file as-is. Run this instead:

$ rake migrate RAILS\_ENV=production

– James
