aspose file tools*
The moose likes Ruby and the fly likes collection_select help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "collection_select help" Watch "collection_select help" New topic
Author

collection_select help

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Hey,

I am writing a rails app and running into some trouble with collection_select, I am using collection_select to create two drop down lists in my application; but when the user (me) selects one then creates a new entry, the pieces of the entry that relate to the select are empty.

Here is what I have in my new.html.erb


And here is my index definition in my controller:



'
Thanks,
Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Did you traced at console?
What request parameters you see?

Spritle Software Blogs
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

The first thing I inspect when I have problems like this is to view the source of the rendered page in my browser. If you inspect yours I'll bet you'll find:
<select name="user[name]">
and
<select name="milestone[id]">

That's a problem because these say "I want to set the id attribute on my User model and the id attribute on my Milestone model." Your model to update is Bet, not User or Milestone.

What you need it to say is "I want to set the user attribute on my Bet model and also the milestone attribute on my Bet model."

It needs to end up looking like:
<select name="bet[user]">
and
<select name="bet[milestone]">

Changing the first two symbols you pass to collection_select will fix this.

In fact, I believe you can even eliminate the first symbol from your parameters by simply calling collection_select against your form object (like you did with the other fields).

Also, there's a shortcut for MyModel.find(:all) of MyModel.all

Hope all this helps!


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: collection_select help