如何在rake任务中调用ActiveSupport方法?
这就是我正在尝试的:
require "active_support"
desc "test"
task :foo => [:environment] do
parse(:categories) do |hash|
# cleanup name
hash[:name] = titlecase(hash[:name])
# ...
end
end
这是我收到的错误:
未定义方法`titlecase' main:Object
我也尝试过:
ActiveSupport::Inflector::titlecase(hash[:name])
导致此错误:
未定义方法“titlecase”ActiveSupport::Inflector:Module
This is what I'm trying:
require "active_support"
desc "test"
task :foo => [:environment] do
parse(:categories) do |hash|
# cleanup name
hash[:name] = titlecase(hash[:name])
# ...
end
end
This is the error I'm getting:
undefined method `titlecase' main:Object
I've also tried:
ActiveSupport::Inflector::titlecase(hash[:name])
Results in this error:
undefined method `titlecase' ActiveSupport::Inflector:Module
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
而不是你正在尝试的事情。它对我有用。
try
instead of what you are trying. it worked for me.