Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby f.select: Syntax for assigning css class?

ENVIRONMENT

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]; Rails 3.2.6; OSX 10.6.8

QUESTION

Having tried many permutations of the following syntax, I have to ask (the probably stupid question), what is the proper syntax for assigning .css classes to Ruby f.select objects?

<%= f.select :fieldname, 
options_for_select( [[ t('selector_instruction_string'), ""]] + countries, 
resource.fieldname), 
html_options { :class => 'Select_100pct' } %>

See last line (broken for display).

This syntax (and many like it) are either ignored, or fail to raise errors (either).

like image 857
mike montagne Avatar asked Dec 04 '22 14:12

mike montagne


1 Answers

To me it seems that, when I read the documentation, your code should be:

<%= f.select :fieldname, options_for_select(...), {}, { :class => 'Select_100pct' } %>

Because you only want to specify html_options, just pass in an empty Hash {} for options.

like image 123
hjblok Avatar answered Mar 13 '23 08:03

hjblok