开发者

How to call ActiveSupport method inside rake task?

开发者 https://www.devze.com 2023-01-13 14:41 出处:网络
This is what I\'m trying: require \"active_support\" desc \"test\" task :foo => [:environment] do parse(:categ开发者_Go百科ories) do |hash|

This is what I'm trying:

require "active_support"

desc "test"
task :foo => [:environment] do
  parse(:categ开发者_Go百科ories) 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


try

hash[:name] = hash[:name].titlecase

instead of what you are trying. it worked for me.

0

精彩评论

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