开发者

Supplying default options for error_messages_for

I have a website with several forms that all pass the same set of arguments to error_messages_for. Is there a way for me to configure rails to use my default arguments other than creating a helper method which wraps error_messages_for with my argu开发者_运维百科ments?


No it's not. The error_messages_for function doesn't relies on any options.

So I guess the best solution is, as you say, to create a helper method to retrieve your arguments.

def my_default_error_options(options = {})
    { :value => true }.merge!(options)
end

error_messages_for my_default_error_options

And if you need some extra options specifically for one call :

error_messages_for my_default_error_options({:value => false})


A quick read of the code suggest you can't. I'd go with the helper route, or monkey patch error_messages_for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜