gpt4 book ai didi

ruby-on-rails - 如何覆盖 Rails 的选择表单助手?

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:33 24 4
gpt4 key购买 nike

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

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

目标是禁用所有选择的标签。

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

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

感谢您的指点。

最佳答案

当您将它发送给 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

关于ruby-on-rails - 如何覆盖 Rails 的选择表单助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com