我使用以下f.select
查询:
= f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => lambda{ |category| category.id == 18 }})
这行给我一个语法错误......为什么?所有的大括号都应该闭合...
我使用以下f.select
查询:
= 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 }})
应该
= f.select(:category_id, @categories, :html_options => {:class => 'select_box', :disabled => lambda{ |category| category.id == 18 }})
您在自己的哈希中有 disabled 选项
根据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' }).
不过,最后一组括号不是必需的。