当我指定参数的值时,它是一个字符串。所以我试着将它变成一个整数,但这不起作用。
代码是这样的:
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
我犯了什么错误?
答案 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