collection_select with :selected option

Thread Solved

Join Date: Nov 2006
Posts: 44
Reputation: amithasija is an unknown quantity at this point 
Solved Threads: 0
amithasija amithasija is offline Offline
Light Poster

collection_select with :selected option

 
0
  #1
Apr 10th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 523
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: collection_select with :selected option

 
0
  #2
Apr 12th, 2007
Originally Posted by amithasija View Post
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.
You need to give more information. What do you want to be selected and when?

If you want a default value put
  1. t.column :favourite_colour_id, :integer, :default => 1
in your migration.

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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 44
Reputation: amithasija is an unknown quantity at this point 
Solved Threads: 0
amithasija amithasija is offline Offline
Light Poster

Re: collection_select with :selected option

 
0
  #3
Apr 13th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 523
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: collection_select with :selected option

 
0
  #4
Apr 14th, 2007
Originally Posted by amithasija View Post
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.
Ah - I see what you mean now.

Try something like this (for this i'm assuming a person has many jobs):

  1. <%= collection_select
  2. :person,
  3. :job_ids,
  4. Job.find(:all),
  5. :id,
  6. :description,
  7. {},
  8. :multiple => true,
  9. :name => 'person[job_ids][]'
  10. %>
Last edited by pty; Apr 14th, 2007 at 11:17 am. Reason: alignment went funny
Note to self... pocket cup
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Ruby
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC