944,159 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Marked Solved
  • Views: 17060
  • Ruby RSS
Apr 10th, 2007
0

collection_select with :selected option

Expand 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
amithasija is offline Offline
44 posts
since Nov 2006
Apr 12th, 2007
0

Re: collection_select with :selected option

Click to Expand / Collapse  Quote originally posted by amithasija ...
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
Ruby Syntax (Toggle Plain Text)
  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.
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005
Apr 13th, 2007
0

Re: collection_select with :selected option

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
amithasija is offline Offline
44 posts
since Nov 2006
Apr 14th, 2007
0

Re: collection_select with :selected option

Click to Expand / Collapse  Quote originally posted by amithasija ...
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):

Ruby Syntax (Toggle Plain Text)
  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
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: Is It Worth Learning Rugby?
Next Thread in Ruby Forum Timeline: Ruby and/or Rails





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC