| | |
collection_select with :selected option
Please support our Ruby advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
•
•
can we use collection_select with :selected option if yes ,plz let me know.if not than plz tell me how to use select instead of collection_select and where to write query in select if i dont want to find all records.
thnx in advance.
If you want a default value put
Ruby Syntax (Toggle Plain Text)
t.column :favourite_colour_id, :integer, :default => 1
If you are loading an existing record (for editing) the correct value should already be selected in the select box.
If you are still stuck please paste your controller and view code.
Note to self... pocket cup
•
•
Join Date: Nov 2006
Posts: 44
Reputation:
Solved Threads: 0
thanx buddy for quick reply,
now i am explaning you the whole scenario.what i have done is ,i have a sample form with collection_select on it with multiple true(suppose five values).on submit selected values goes into database(suppose two) coreesponding to particular id.now when i again open the page i want the values from database comes as selected(two values that are coming from database as highlighted or selected).and thanx for all your help till now and in future.
now i am explaning you the whole scenario.what i have done is ,i have a sample form with collection_select on it with multiple true(suppose five values).on submit selected values goes into database(suppose two) coreesponding to particular id.now when i again open the page i want the values from database comes as selected(two values that are coming from database as highlighted or selected).and thanx for all your help till now and in future.
•
•
•
•
thanx buddy for quick reply,
now i am explaning you the whole scenario.what i have done is ,i have a sample form with collection_select on it with multiple true(suppose five values).on submit selected values goes into database(suppose two) coreesponding to particular id.now when i again open the page i want the values from database comes as selected(two values that are coming from database as highlighted or selected).and thanx for all your help till now and in future.
Try something like this (for this i'm assuming a person has many jobs):
Ruby Syntax (Toggle Plain Text)
<%= collection_select :person, :job_ids, Job.find(:all), :id, :description, {}, :multiple => true, :name => 'person[job_ids][]' %>
Last edited by pty; Apr 14th, 2007 at 11:17 am. Reason: alignment went funny
Note to self... pocket cup
![]() |
Similar Threads
- Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource (PHP)
- return a value from javascript (PHP)
- Error message when trying to open an external file in C++ program (C++)
- problems selecting minimum when searching (ASP)
- Windows rubicks cube - BSOD (Windows NT / 2000 / XP)
- Add an Item to the Send To Menu (Windows tips 'n' tweaks)
Other Threads in the Ruby Forum
- Previous Thread: Is It Worth Learning Rugby?
- Next Thread: Ruby and/or Rails
| Thread Tools | Search this Thread |
Tag cloud for Ruby





