无法将传递的参数更改为rake任务

时间:2014-10-02 09:29:38

标签: ruby-on-rails ruby

当我指定参数的值时,它是一个字符串。所以我试着将它变成一个整数,但这不起作用。

代码是这样的:

task :fetch_video, [:fetch_number] => :environment do |t, args|
  args.with_defaults(:fetch_number => 4)
  args.fetch_number = args.fetch_number.to_i
  puts args.fetch_number.class

  #run rake fetch_video[10],
  #returns: String
end

我犯了什么错误?

1 个答案:

答案 0 :(得分:1)

您正在尝试撰写args变量,我认为您无法做到这一点。试试这个:

task :fetch_video, [:fetch_number] => :environment do |t, args|
  args.with_defaults(:fetch_number => 4)
  local_fetch_number = args.fetch_number.to_i
  puts local_fetch_number.class
end