【问题标题】:How to override Rails' select form helper?如何覆盖 Rails 的选择表单助手?
【发布时间】:2012-11-11 16:53:16
【问题描述】:

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

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

目标是disable所有选择标签。

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

谁能告诉我这里缺少什么?

感谢您的任何指点。

【问题讨论】:

  • 抱歉,没明白什么实际上不起作用?
  • 你试过:disabled => "disabled"吗?
  • 我刚做了,结果一样...

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


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2014-12-07
    • 2018-10-26
    • 2014-04-18
    • 2015-08-27
    • 2013-02-27
    • 1970-01-01
    相关资源
    最近更新 更多