0

我使用以下f.select查询:

= f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => lambda{ |category| category.id == 18 }})

这行给我一个语法错误......为什么?所有的大括号都应该闭合...

4

2 回答 2

2
= f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => lambda{ |category| category.id == 18 }})

应该

= f.select(:category_id, @categories, :html_options => {:class => 'select_box', :disabled => lambda{ |category| category.id == 18 }})

您在自己的哈希中有 disabled 选项

于 2012-07-06T15:50:03.503 回答
1

根据api,方法定义为

f.select(method, choices, options = {}, html_options = {})

where:disabled是一个选项,:class将是一个 html_option,所以调用应该写成

f.select(:category_id, @categories, {:disabled => lambda{ |category| category.id == 18 }}, { :class => 'select_box' }).

不过,最后一组括号不是必需的。

于 2012-07-06T16:03:34.487 回答