Hi, I have a column of data with repeated as mentioned below. *column_name* Acer Lenova HP Lenova Acer Acer Lenova I need to populate this column in a combo box without repeated data as mentioned below *combo box* Acer Lenova HP I tried as <%= collection_select(:column_name, TableName.all)%> "table_names" is a table and "column_name" is a column needed to populate. -- With Regards Palani Kannan. K -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
a. Get your DB Access out of the views... b. Read The Fine Manual on collection_select c. Controller: @vendors = TableName.find(:all).uniq or some variant thereof With a lot of records, you might want to use a find_by_sql and let the DB do the work with a "SELECT DISTINCT..." d. View: <%= collection_select("model_to_populate", "column_to_populate", @vendors, "id", "vendor_name_field") %> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K
2010-Sep-09 10:03 UTC
Re: Re: Populate combo box from database without repeatness
Hi, Ar Chron, It works... Thank you for kind help. But, I am unable to use params[:id] to get the selected value from collection_select. how i can get selected value to params. I need the flow collection_select (value selected) -> param[:id]-> find SQL row.. On 8 September 2010 17:51, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> a. Get your DB Access out of the views... > > b. Read The Fine Manual on collection_select > > c. Controller: > > @vendors = TableName.find(:all).uniq or some variant thereof > > With a lot of records, you might want to use a find_by_sql and let the > DB do the work with a "SELECT DISTINCT..." > > d. View: > > <%= collection_select("model_to_populate", "column_to_populate", > @vendors, "id", "vendor_name_field") %> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- With Regards Palani Kannan. K Office: +49-531-2616-226 Mobile: +4917647098166 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar Chron
2010-Sep-09 14:39 UTC
Re: Re: Populate combo box from database without repeatness
PalaniKannan K wrote:> But, I am unable to use params[:id] to get the selected value > from collection_select. how i can get selected value to params. > > I need the flow > collection_select (value selected) -> param[:id]-> find SQL row.. >The selected value is in params already, just not where you''re looking. Take a look in your log at the post request that rails receives when you submit the form... this information is all readily available there. You should see something like: Parameters: {"utf8"=>"blah1", "authenticity_token"=>"blah2", "model_to_populate"=>{"column_to_populate"=>"blah3",...}, "commit"=>"blah4", "id"=>"blah5"} In your controller code, params[:id] is the id of the ''model_to_populate'' (blah5) params[:model_to_populate][:column_to_populate] is the value stored by the collection_select statement in the view (blah3) Parsing through and understanding your log files is something everyone should be comfortable with. It''s usually the first stop in performing triage on unexpected behaviors. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K
2010-Sep-09 14:46 UTC
Re: Re: Re: Populate combo box from database without repeatness
HI, Its populated... Thank you verymuch... On 9 September 2010 16:39, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> PalaniKannan K wrote: > > But, I am unable to use params[:id] to get the selected value > > from collection_select. how i can get selected value to params. > > > > I need the flow > > collection_select (value selected) -> param[:id]-> find SQL row.. > > > > The selected value is in params already, just not where you''re looking. > > Take a look in your log at the post request that rails receives when you > submit the form... this information is all readily available there. > > You should see something like: > Parameters: {"utf8"=>"blah1", "authenticity_token"=>"blah2", > "model_to_populate"=>{"column_to_populate"=>"blah3",...}, > "commit"=>"blah4", "id"=>"blah5"} > > In your controller code, > > params[:id] is the id of the ''model_to_populate'' (blah5) > > params[:model_to_populate][:column_to_populate] is the value stored by > the collection_select statement in the view (blah3) > > Parsing through and understanding your log files is something everyone > should be comfortable with. It''s usually the first stop in performing > triage on unexpected behaviors. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- With Regards Palani Kannan. K Office: +49-531-2616-226 Mobile: +4917647098166 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.