User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Ruby section within the Web Development category of DaniWeb, a massive community of 362,358 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,528 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Views: 6665 | Replies: 3 | Solved
Reply
Join Date: Nov 2006
Location: new delhi
Posts: 38
Reputation: amithasija is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
amithasija amithasija is offline Offline
Light Poster

Help collection_select with :selected option

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation: pty is on a distinguished road 
Rep Power: 3
Solved Threads: 30
pty's Avatar
pty pty is offline Offline
Posting Pro in Training

Re: collection_select with :selected option

  #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
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  
Join Date: Nov 2006
Location: new delhi
Posts: 38
Reputation: amithasija is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
amithasija amithasija is offline Offline
Light Poster

Re: collection_select with :selected option

  #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  
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation: pty is on a distinguished road 
Rep Power: 3
Solved Threads: 30
pty's Avatar
pty pty is offline Offline
Posting Pro in Training

Re: collection_select with :selected option

  #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):

<%= collection_select 
	:person, 
	:job_ids,
	Job.find(:all),
	:id, 
	:description,
	{},
	:multiple => true,
	:name => 'person[job_ids][]' 
%>
Last edited by pty : Apr 14th, 2007 at 10:17 am. Reason: alignment went funny
Note to self... pocket cup
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Ruby Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Ruby Forum

All times are GMT -4. The time now is 11:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC