2012-11-11 33 views
2

我试图重写Rails的形式选择助手这样的:如何覆盖Rails的select form helper?

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

目标是disable所有选择标签。

不幸的是,它根本没有工作。选择框根本不会被禁用,也不会引发错误。我已经验证了该方法在窗体中被正确调用,所以不能成为问题。

有人可以告诉我我在这里失踪了吗?

感谢您的指点。

+0

对不起,没有得到什么实际上不工作? – HungryCoder

+0

您尝试过':disabled =>“disabled”吗? – PinnyM

+0

我只是做了,工作相同... – Tintin81

回答

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 
+0

这样做的伎俩,非常感谢您的帮助! – Tintin81