如何使用ActiveSupport
模块中定义的方法?
例如,我想使用camelize
方法。
我尝试了此代码,但它无法解决undefined method
错误。
require 'active_support'
"foo_bar".camelize
答案 0 :(得分:5)
您可以只需要提供camelize的部分,而不是所有的Active Support:
require 'active_support/core_ext/string'
"camel_this".camelize => "CamelThis"
答案 1 :(得分:3)
您需要require 'active_support/all'
这解释了......
http://guides.rubyonrails.org/active_support_core_extensions.html