• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

collection_select help

 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you traced at console?
What request parameters you see?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic