Form_for and Multiple Models Being Saved

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

On 9/24/06, HH [email protected] 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

I have a very weird problem where no one can connect to my server
(“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
=> 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 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 on port 8000, telnet says:
“telnet: Unable to connect to remote host: No route to host”

However, I can ping 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

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

Thanks!
-Jason

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

This might be blocked by your firewall.

Vish

Hello Jason !

2006/9/28, Jason F. [email protected]:

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://piston.rubyforge.org/

That did it… thanks JDL and Francois!

-Jason

On 9/28/06, Jason F. [email protected] wrote:

development:
database: myproject_production

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

$ rake migrate RAILS_ENV=production

– James

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs