I have a drop down of country''s and I would like the USA to be the first displayed. I have tried: <select id = "user_w_country" name ="user[w_country]" onchange "<%=func%>"> <%= options_from_collection_for_select @country, ''id'', ''country'', :selected => Countrycode.find_by_country(''USA'').id %> </select> It doesn''t complai9n about the code but it doesn''t work either. The documentation for the options_from_collection_for_select says the third argument is a select option, but I am obviously doing something wrong. Any ideas? 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 -~----------~----~----~----~------~----~------~--~---
Can anyone tell me if am putting the select in the right place? -- 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 -~----------~----~----~----~------~----~------~--~---
If you''re going to use options_from_collection_for_select it''s probably also worth using the other rails helpers as well. <%= select_tag "user_w_country", @country, :id, :country, Countrycode.find_by_country(''USA'') %> <%= observe_field ''user_w_country'', :function => func %> HTH, AndyV On Apr 4, 9:56 am, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Can anyone tell me if am putting the select in the right place? > -- > 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 -~----------~----~----~----~------~----~------~--~---
I have this collection and I am trying to display from the list which one I would like to have selected when I am rendering a dropdown. Here is what I got: <%= options_from_collection_for_select @country, ''id'', ''country'', :selected => ''USA'' %> Displays the list fine (this is a dropdown of country''s by the way). What I would like it to do is pick out USA a the selected option when you drop down the select box, but so far nothin''. Has anyone done this? What do I have to do to select an entry from the options_from_collection_for_select? 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 -~----------~----~----~----~------~----~------~--~---
Hi, That doesn''t make a WHOLE lot of sense. options_from_collection_for_select will give you <option> tags. It takes a collection, and then the value and display value methods to send to the objects in the collection as it traverses them, creating the option tags. Thus, @country, here, would be assumedly a list of country objects which take the id and country methods as their value and display values respectively. There is an optional fourth value, which is the VALUE to match with the object you want. For instance: <%= options_from_collection_for_select @country, ''id'', ''country'', @selected_country %> where @selected_country is the id of the country you want selected. Julian. Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #3 out NOW! http://sensei.zenunit.com/ On 08/04/2008, at 7:53 AM, Shandy Nantz wrote:> > I have this collection and I am trying to display from the list which > one I would like to have selected when I am rendering a dropdown. Here > is what I got: > > <%= options_from_collection_for_select @country, ''id'', ''country'', > :selected => ''USA'' %> > > Displays the list fine (this is a dropdown of country''s by the way). > What I would like it to do is pick out USA a the selected option when > you drop down the select box, but so far nothin''. Has anyone done > this? > What do I have to do to select an entry from the > options_from_collection_for_select? 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 -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- options_from_collection_for_select
- options_from_collection_for_select & multiple columns
- selected value for options_from_collection_for_select
- Unable to get selected option with options_from_collection_for_select
- habtm and options_from_collection_for_select [1.0.0]