2

我正在尝试像这样覆盖 Rails 的表单选择助手:

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

目标是disable所有选择标签。

不幸的是,它根本不起作用。选择框根本不会被禁用,也不会引发错误。我已经验证了该方法在表单中被正确调用,所以这不是问题。

谁能告诉我我在这里想念什么?

感谢您的任何指示。

4

1 回答 1

1

当您将选项发送给 super 时,您正在重置选项选项。

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

  # Don't do this!  By doing this you're *always* sending empty objects for
  # options and html_options to super.
  #super(method, choices, options = {}, html_options = {})

  # Do this!
  super(method, choices, options, html_options)
end
于 2012-11-11T20:10:31.510 回答