I have posted before about collection_select but have not gotten what I am working on to work. I have even searched the archives for similar discussions and am at a little bit of a loss because some have claimed to have fixed the problem but I still can''t get it to work for me. What I am trying to do is simply add the :selected option to the collection_select helper. This is what I got: <%= collection_select("user", "w_country" , Countrycode.find( :all, :order => ''country'' ), :id, :country, :selected => 159573, :onchange => func ) %> I simply want it to select the country code that has the specified id. The onchange is for when a selection is made the drop down reverts back to a link on a form. Has anyone gotten the combination of these two to work? Thanks, -S -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Apr 18, 2008 at 5:23 AM, Shandy Nantz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> <%= collection_select("user", "w_country" , Countrycode.find( :all, > :order => > ''country'' ), :id, :country, :selected => 159573, :onchange => func ) > %>I had something similar. What I ended up doing is manually coding the select tag, and then adding an ''options for select'' tag underneath within the manual select tag. Works fine. Remember, the helper methods are there to help, but if they get in the way, don''t be afraid to get rid of them - or make a new one that does exactly what you want. Mikel --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I am attempting to populate a collection_select object with data from a separate table than the one the collection will be displayed. Specifically, I would like to add a new ''project'', and in one of the fields, I would like to have a drop down list which shows different project types. Any advice on how to do this would be greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
controller -------------------- #DDM = Drop Down Menu #example your table project only contains column : ID & PROJECT_NAME @project_list = Project.find_all in VIEW ---------- [1] SELECT_TAG Code: <%= select_tag "project","<option value=\"0\"> Select Project</option>"+ options_for_select(@project_list.map(&:project_name).sort.uniq) %> [2] COLLECTION_SELECT <%= collection_select(:project, :id, @project_list, :id, :project_name, options ={:prompt => "-Select Project"}, :class =>"project") %> Reinhart http://teapoci.blogspot.com -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for the quick response. However, I must not have been clear in my question: Assume that I have two tables: project, type PROJECT contains columns: ID PROJECT_NAME TYPE_ID TYPE contains: ID TYPE_NAME When I create a new project, I would like to have a #DDM, populated by the TYPE_NAME field. On Apr 23, 10:32 pm, Visit Indonesia 2008 <rails-mailing-l...@andreas- s.net> wrote:> controller > -------------------- > > #DDM = Drop Down Menu > #example your table project only contains column : ID & PROJECT_NAME > > @project_list = Project.find_all > > in VIEW > ---------- > [1] SELECT_TAG > Code: > <%= select_tag "project","<option value=\"0\"> > Select Project</option>"+ > options_for_select(@project_list.map(&:project_name).sort.uniq) %> > > [2] COLLECTION_SELECT > > <%= collection_select(:project, :id, @project_list, :id, :project_name, > options ={:prompt => "-Select Project"}, :class =>"project") %> > > Reinharthttp://teapoci.blogspot.com > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
CONTROLLER : @type_list = Project.find(:all, :include => {:types=>{} }).collect{|x| x.type.type_name}.sort.uniq in VIEW : ---------- <%= select_tag "type_name","<option value=\"0\"> Select Project Type</option>"+ options_for_select(@type_list) %> OR <%= select_tag "type_name", options_for_select(@type_list, @type_list[0]) %> Cheer, Reinhart http://teapoci.blogspot.com -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, that is a very tricky solution. I was starting from an empty project table, with a populated type table. I will include some dummy projects to feed this list. Am I correct in assuming that this is the necessary solution to this? It seems that querying the large product table will be more expensive than simply populating off of the smaller type table. On Apr 23, 11:21 pm, Visit Indonesia 2008 <rails-mailing-l...@andreas- s.net> wrote:> CONTROLLER : > > @type_list = Project.find(:all, :include => {:types=>{} }).collect{|x| > x.type.type_name}.sort.uniq > > in VIEW : > ---------- > > <%= select_tag "type_name","<option value=\"0\"> > Select Project Type</option>"+ > options_for_select(@type_list) %> > > OR > > <%= select_tag "type_name", options_for_select(@type_list, > @type_list[0]) %> > > Cheer, > > Reinharthttp://teapoci.blogspot.com > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 23 Apr 2008, at 16:38, erik wrote:> > Thanks, that is a very tricky solution. I was starting from an empty > project table, with a populated type table. I will include some dummy > projects to feed this list. Am I correct in assuming that this is the > necessary solution to this? It seems that querying the large product > table will be more expensive than simply populating off of the smaller > type table. >If you''ve got the types in a table, then collection_select ''project'', ''type'', Type.find(:all), :type_name, :id (assuming you''re editing the instance variable @person). Before you do any of this, choose a name that isn''t type: that''s used by rails for single table inheritance Fred> On Apr 23, 11:21 pm, Visit Indonesia 2008 <rails-mailing-l...@andreas- > s.net> wrote: >> CONTROLLER : >> >> @type_list = Project.find(:all, :include => {:types=>{} }).collect{| >> x| >> x.type.type_name}.sort.uniq >> >> in VIEW : >> ---------- >> >> <%= select_tag "type_name","<option value=\"0\"> >> Select Project Type</option>"+ >> options_for_select(@type_list) %> >> >> OR >> >> <%= select_tag "type_name", options_for_select(@type_list, >> @type_list[0]) %> >> >> Cheer, >> >> Reinharthttp://teapoci.blogspot.com >> >> -- >> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Perfect. I have been struggling with that all day. It worked like magic. Thanks for the help. -Erik On Apr 23, 11:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 23 Apr 2008, at 16:38, erik wrote: > > > > > Thanks, that is a very tricky solution. I was starting from an empty > > project table, with a populated type table. I will include some dummy > > projects to feed this list. Am I correct in assuming that this is the > > necessary solution to this? It seems that querying the large product > > table will be more expensive than simply populating off of the smaller > > type table. > > If you''ve got the types in a table, then > > collection_select ''project'', ''type'', Type.find(:all), :type_name, :id > > (assuming you''re editing the instance variable @person). Before you do > any of this, choose a name that isn''t type: that''s used by rails for > single table inheritance > > Fred > > > On Apr 23, 11:21 pm, Visit Indonesia 2008 <rails-mailing-l...@andreas- > > s.net> wrote: > >> CONTROLLER : > > >> @type_list = Project.find(:all, :include => {:types=>{} }).collect{| > >> x| > >> x.type.type_name}.sort.uniq > > >> in VIEW : > >> ---------- > > >> <%= select_tag "type_name","<option value=\"0\"> > >> Select Project Type</option>"+ > >> options_for_select(@type_list) %> > > >> OR > > >> <%= select_tag "type_name", options_for_select(@type_list, > >> @type_list[0]) %> > > >> Cheer, > > >> Reinharthttp://teapoci.blogspot.com > > >> -- > >> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi is it possible to manually add an option to collection_select I have the following code and want to add "Add Customer" to the bottom of the options list. <% @customers = Customer.find(:all, :order => "company")%> <%= f.collection_select(:customer_id, @customers,:id, :company) %> Thanks Martin -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/14/08, Martin Evans <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi is it possible to manually add an option to collection_select > I have the following code and want to add "Add Customer" to the bottom > of the options list. > > <% @customers = Customer.find(:all, :order => "company")%>@customers is an array, so you want to use the array method ''+'' to add your new element to it. http://www.ruby-doc.org/core/classes/Array.html#M002232> <%= f.collection_select(:customer_id, @customers,:id, :company) %>-- Greg Donald http://destiney.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald wrote:> On 5/14/08, Martin Evans <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Hi is it possible to manually add an option to collection_select >> I have the following code and want to add "Add Customer" to the bottom >> of the options list. >> >> <% @customers = Customer.find(:all, :order => "company")%> > > @customers is an array, so you want to use the array method ''+'' to add > your new element to it. > > http://www.ruby-doc.org/core/classes/Array.html#M002232 > >> <%= f.collection_select(:customer_id, @customers,:id, :company) %> > > > -- > Greg Donald > http://destiney.com/I can see that it is an array and I''ve looked at the documentation and have tried a few ways of getting it to work but have failed miserably can you give me an example of how I would add an option manually this is what I have for the select @customers = Customer.find(:all, :select => "id, company") => [#<Customer id: 6, company: "Ernie''s Bakery">, #<Customer id: 7, company: "Young''s the Bakers">, #<Customer id: 8, company: "Suggs Newsagents">] thanks Martin -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You probably want to get a little lower-level than collection_select, which is designed to simplify creating your select tag from a collection of objects. Since you''re adding an option to that collection, you should go with either select_tag, or select, adding options_for_select( Customer.find(:all).map{|c|[c.id,c.company} + [''add_a_customer'', ''Add Customer'']) as the "options" parameter. Take a look at the API for the usage of "select" or "select_tag". Also depends on whether you''re using a form helper. On May 26, 3:45 pm, Martin Evans <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Greg Donald wrote: > > On 5/14/08, Martin Evans <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > >> Hi is it possible to manually add an option to collection_select > >> I have the following code and want to add "Add Customer" to the bottom > >> of the options list. > > >> <% @customers = Customer.find(:all, :order => "company")%> > > > @customers is an array, so you want to use the array method ''+'' to add > > your new element to it. > > >http://www.ruby-doc.org/core/classes/Array.html#M002232 > > >> <%= f.collection_select(:customer_id, @customers,:id, :company) %> > > > -- > > Greg Donald > >http://destiney.com/ > > I can see that it is an array and I''ve looked at the documentation and > have tried a few ways of getting it to work but have failed miserably > can you give me an example of how I would add an option manually this is > what I have for the select > @customers = Customer.find(:all, :select => "id, company") > => [#<Customer id: 6, company: "Ernie''s Bakery">, #<Customer id: 7, > company: "Young''s the Bakers">, #<Customer id: 8, company: "Suggs > Newsagents">] > > thanks > Martin > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---