如何在Rails上设置默认属性选择表单助手?

时间:2012-11-10 18:36:56

标签: ruby-on-rails ruby ruby-on-rails-3

我正在尝试使用自定义表单帮助器覆盖Rails的select方法,以便默认情况下所有选择框都会获得disabled属性:

class LabelFormBuilder < ActionView::Helpers::FormBuilder

  def select(method, choices, options = {}, html_options = {})
    html_options.reverse_merge! :disabled => true
    super(method, choices, options = {}, html_options = {})
  end

end

问题是代码不起作用,并且它不会像选择框的呈现方式那样改变任何东西。它也不会抛出错误。

这是我用来调用函数的视图代码:

<%= f.select(:person_id, current_user.person_names, {:prompt => 'Please select...'}) %>

我在这里缺少什么?

感谢您的帮助......

1 个答案:

答案 0 :(得分:0)

尝试使用

<%= f.select(:person_id, current_user.person_names, {}, {:prompt => 'Please select...'}) %>
相关问题