Forum: Ruby on Rails hard coded drop down menu help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D7216ed484f5c4af81a726cbe2337369?d=identicon&s=25 Jimmy Perrine (jimmyp56)
on 2009-03-04 22:57
I currently have a drop down menu selection in an input form with
hardcoded values, the problem I'm having is I want to use multiple word
entries that users can select from, is there anyway of doing that?

here is my code as it exists now

<%= f.label :category, "Category" %><br />
<%= select 'article', 'category', %w(Cooperation
EnvironmentalSustainability BusinessDevelopment Transportation
Streetscape DenseMixedUse) %>


obviously I need some of these to be two words as one entry instead of
being multiple entries

please help!
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-03-04 23:20
(Received via mailing list)
On Mar 4, 2009, at 4:57 PM, Jimmy Perrine wrote:
> Streetscape DenseMixedUse) %>
>
>
> obviously I need some of these to be two words as one entry instead of
> being multiple entries
>
> please help!


Just skip the shorthand:

['Cooperation', 'Environmental Sustainability', 'Business Development',
  'Transportation', 'Streetscape', 'Dense Mixed Use' ]

Even better might be a model to return the choices.

class Category
   def self.choices_for_select
     ['Cooperation', 'Environmental Sustainability', 'Business
Development',
      'Transportation', 'Streetscape', 'Dense Mixed Use' ]
   end
end

<%= select 'article', 'category', Category.choices_for_select %>

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2009-03-04 23:36
Rob Biedenharn wrote:
> Just skip the shorthand:

It should also work by escaping the spaces:
%w{Cooperation
Environmental\ Sustainability Business\ Development Transportation
Streetscape Dense\ Mixed\ Use}

Note: noticed the curly braces %w{list of words}
D7216ed484f5c4af81a726cbe2337369?d=identicon&s=25 Jimmy Perrine (jimmyp56)
on 2009-03-05 01:14
thanks guys, that was perfect
This topic is locked and can not be replied to.