环境
ruby 1.9.3p194(2012-04-20修订版35410)[x86_64-darwin10.8.0]; Rails 3.2.6; OSX 10.6.8
题
尝试了以下语法的许多排列后,我不得不问(可能是愚蠢的问题),将.css类分配给Ruby f.select对象的正确语法是什么?
<%= f.select :fieldname,
options_for_select( [[ t('selector_instruction_string'), ""]] + countries,
resource.fieldname),
html_options { :class => 'Select_100pct' } %>
Run Code Online (Sandbox Code Playgroud)
见最后一行(打破显示).
这种语法(以及许多类似的)被忽略,或者无法引发错误(或者).
hjb*_*lok 13
对我而言,当我阅读文档时,您的代码应该是:
<%= f.select :fieldname, options_for_select(...), {}, { :class => 'Select_100pct' } %>
Run Code Online (Sandbox Code Playgroud)
因为你只想指定html_options,只需传入一个空的Hash {}for options.