Hey, I am trying to get a select list with a selected value in it. Even if I put in an integer, like this, <%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", 3)) %> the list still displays the first option (No Contract) in the list. What am I doing wrong? I''ve looked all over and it looks like this should be working. -- 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 -~----------~----~----~----~------~----~------~--~---
Joe Peck wrote:> Hey, > > I am trying to get a select list with a selected value in it. Even if I > put in an integer, like this, > > <%= select_tag(fruit.id, "<option>No Contract</option>" + > options_from_collection_for_select(@fruit_types, "id", "kind", 3)) %> > > the list still displays the first option (No Contract) in the list. > > What am I doing wrong? I''ve looked all over and it looks like this > should be working.I''ve tried using "to_i", but it still generates the wrong "selected" value. <%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", fruit.kind_id.to_i)) %> generates <select id="70" name="70"><option>No Contract</option><option value="3" selected="selected">40 bucks for a PR 10 Links</option> <option value="7">Antidisestablishmentarialism</option></select> -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-31 19:47 UTC
Re: selected value for options_from_collection_for_select
On 31 Jul 2008, at 19:20, Joe Peck wrote:> > Joe Peck wrote: >> Hey, >> >> I am trying to get a select list with a selected value in it. Even >> if I >> put in an integer, like this, >> >> <%= select_tag(fruit.id, "<option>No Contract</option>" + >> options_from_collection_for_select(@fruit_types, "id", "kind", 3)) %> >> >> the list still displays the first option (No Contract) in the list. >> >> What am I doing wrong? I''ve looked all over and it looks like this >> should be working. > > I''ve tried using "to_i", but it still generates the wrong "selected" > value. > <%= select_tag(fruit.id, "<option>No Contract</option>" + > options_from_collection_for_select(@fruit_types, "id", "kind", > fruit.kind_id.to_i)) %> > > generates > > <select id="70" name="70"><option>No Contract</option><option > value="3" > selected="selected">40 bucks for a PR 10 Links</option> > <option value="7">Antidisestablishmentarialism</option></select>What''s the value of fruit.kind_id ? Fred> > -- > 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 -~----------~----~----~----~------~----~------~--~---