4

环境

红宝石 1.9.3p194(2012-04-20 修订版 35410)[x86_64-darwin10.8.0];导轨 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' } %>

见最后一行(为了显示而断开)。

这种语法(以及许多类似的语法)要么被忽略,要么无法引发错误(或者)。

4

1 回答 1

16

在我看来,当我阅读文档时,您的代码应该是:

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

因为您只想指定html_options,所以只需传入一个空的 Hash {}for options

于 2012-09-19T17:14:47.630 回答