I am trying to create a form dropdown select field and I would like to use an array to build it. My code is: <select name="order[ship_to_state]" id="order_ship_to_state"> <% states = ["Alabama", "Alaska", "Alberta", "Arizona", "Arkansas" ] states.each do | state | %> <option value="<% "#{state}" %>"> <% "#{state}" %></option> <% end %> </select> But I get an empty dropdown. What should I change to make this happen? Thanks, Elle --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try: states = [''Alabama'', ''Alaska'', ''Denial''].freeze collection_select(:order, :ship_to_state, states.map{|s| [s, s]}, :first, :first) It''s air-code (untried, untested), but might get you on the right track. On Oct 29, 2007, at 11:01 PM, elle wrote:> > I am trying to create a form dropdown select field and I would like to > use an array to build it. > > My code is: > <select name="order[ship_to_state]" id="order_ship_to_state"> > <% states = ["Alabama", "Alaska", "Alberta", "Arizona", > "Arkansas" ] > > states.each do | state | %> > <option value="<% "#{state}" %>"> <% "#{state}" %></option> > <% end %> > </select> > > But I get an empty dropdown. > > What should I change to make this happen? > > Thanks, > Elle > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Not working. Other solution? Elle On Oct 30, 5:24 pm, "s.ross" <cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try: > > states = [''Alabama'', ''Alaska'', ''Denial''].freeze > collection_select(:order, :ship_to_state, states.map{|s| [s, > s]}, :first, :first) > > It''s air-code (untried, untested), but might get you on the right track. > > On Oct 29, 2007, at 11:01 PM, elle wrote: > > > > > I am trying to create a form dropdown select field and I would like to > > use an array to build it. > > > My code is: > > <select name="order[ship_to_state]" id="order_ship_to_state"> > > <% states = ["Alabama", "Alaska", "Alberta", "Arizona", > > "Arkansas" ] > > > states.each do | state | %> > > <option value="<% "#{state}" %>"> <% "#{state}" %></option> > > <% end %> > > </select> > > > But I get an empty dropdown. > > > What should I change to make this happen? > > > Thanks, > > Elle--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> states.each do | state | %> > <option value="<% "#{state}" %>"> <% "#{state}" %></option> > <% end %> > </select> > > But I get an empty dropdown.Hi Elle, You seem to be using the ruby tags that don''t output their content i.e. <% %> Have you tried using <%= %>? Robin --~--~---------~--~----~------------~-------~--~----~ 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 Oct 30, 2007 12:14 PM, Robin Fisher <robinjfisher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > states.each do | state | %> > > <option value="<% "#{state}" %>"> <% "#{state}" %></option> > > <% end %> > > </select> > > > > But I get an empty dropdown. > > Hi Elle, > > You seem to be using the ruby tags that don''t output their content > i.e. <% %> Have you tried using <%= %>? > > Robin > > > > > >Also, am I the only one that sees no point in wrapping ''state'' as a string in itself? I mean it''s a string anyway. You could achieve the same with just <%= state %>, making for more readable code -- is there an advantage I am not aware of in using the <%= "#{state}" %> way? -- Edd Morgan http://www.eddm.co.uk +44 (0) 7805 089097 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Perhaps I wasn''t clear: <% states = [''Alabama'', ''Alaska'', ''Denial''].freeze %> <%= collection_select(:order, :ship_to_state, states.map{|s| [s, s]}, :first, :first) %> This should generate a <select> tag for the instance variable :order that affects the ship_to_state attribute. It should contain a <select> tag for each state with a value and display element exactly the same: The name of the state. What, specifically, is not working? On Oct 29, 2007, at 11:57 PM, elle wrote:> > Not working. Other solution? > > > Elle > > > On Oct 30, 5:24 pm, "s.ross" <cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Try: >> >> states = [''Alabama'', ''Alaska'', ''Denial''].freeze >> collection_select(:order, :ship_to_state, states.map{|s| [s, >> s]}, :first, :first) >> >> It''s air-code (untried, untested), but might get you on the right >> track. >> >> On Oct 29, 2007, at 11:01 PM, elle wrote: >> >> >> >>> I am trying to create a form dropdown select field and I would >>> like to >>> use an array to build it. >> >>> My code is: >>> <select name="order[ship_to_state]" id="order_ship_to_state"> >>> <% states = ["Alabama", "Alaska", "Alberta", "Arizona", >>> "Arkansas" ] >> >>> states.each do | state | %> >>> <option value="<% "#{state}" %>"> <% "#{state}" %></option> >>> <% end %> >>> </select> >> >>> But I get an empty dropdown. >> >>> What should I change to make this happen? >> >>> Thanks, >>> Elle > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<<<<<< <option value="<% "#{state}" %>"> <% "#{state}" %></option>>>>>>> <option value="<% "#{state}" %>"> <%= "#{state}" %></option>On Oct 30, 11:01 am, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to create a form dropdown select field and I would like to > use an array to build it. > > My code is: > <select name="order[ship_to_state]" id="order_ship_to_state"> > <% states = ["Alabama", "Alaska", "Alberta", "Arizona", > "Arkansas" ] > > states.each do | state | %> > <option value="<% "#{state}" %>"> <% "#{state}" %></option> > <% end %> > </select> > > But I get an empty dropdown. > > What should I change to make this happen? > > Thanks, > Elle--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Also, am I the only one that sees no point in wrapping ''state'' as a > string in itself? I mean it''s a string anyway. You could achieve the > same with just <%= state %>, making for more readable code -- is there > an advantage I am not aware of in using the <%= "#{state}" %> way?No, you''re not. I thought the same thing but was at work and couldn''t linger over the question too long. I don''t see that there is any additional benefit. Robin --~--~---------~--~----~------------~-------~--~----~ 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''m so silly to forget to add as in <%= state %> I''m not at my computer at the moment. Will try this a bit later. Cheers, Elle On Oct 31, 7:22 am, Robin Fisher <robinjfis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Also, am I the only one that sees no point in wrapping ''state'' as a > > string in itself? I mean it''s a string anyway. You could achieve the > > same with just <%= state %>, making for more readable code -- is there > > an advantage I am not aware of in using the <%= "#{state}" %> way? > > No, you''re not. I thought the same thing but was at work and couldn''t > linger over the question too long. I don''t see that there is any > additional benefit. > > Robin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well, my original code works by just adding the = sign. Silly me. Thanks guys, Elle On Oct 31, 6:51 am, elle <wazne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m so silly to forget to add > as in <%= state %> > I''m not at my computer at the moment. Will try this a bit later. > > Cheers, > Elle > > On Oct 31, 7:22 am, Robin Fisher <robinjfis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Also, am I the only one that sees no point in wrapping ''state'' as a > > > string in itself? I mean it''s a string anyway. You could achieve the > > > same with just <%= state %>, making for more readable code -- is there > > > an advantage I am not aware of in using the <%= "#{state}" %> way? > > > No, you''re not. I thought the same thing but was at work and couldn''t > > linger over the question too long. I don''t see that there is any > > additional benefit. > > > Robin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---