为什么它不知道如何构建这个任务?

Why doesn't it know how to build this task?

所以我在 rails 运行ning on jruby 中有以下任务:

desc "Creates a new site with args: name, api_url (must be http(s)://api.something.com/v1/ - note the ending slash), api_key"
task :add_new_site, [:name, :api_url, :api_key] => :enviroment do | t, args |
  if !Site.find_by_site_name(args[:name])
    new_site = Site.new(site_name: args[:name], site_api_url: args[:api_url], site_api_key: args[:api_key])
    if new_site.save!
      puts "Created new Site: " + args[:name]
    end
  else
    puts "This site already exists."
  end
end

当我运行这样的时候:

$ bin/rake add_new_site['sample', 'sample.com', 'addasdsd']
rake aborted!
Don't know how to build task 'add_new_site[sample,'

可以看到错误。

收到这个我做错了什么?我还有其他需要一个参数的任务,它们似乎工作正常。

注意: 是的,这是在 .rake 而不是 .rb 文件中

更新一:

从下面的输出可以看出,我看到了这个任务的要求,试了一下还是失败了:

$ bin/rake -T add_new_site ['sample', 'sample.com', 'addasdsd']
rake add_new_site[name,api_url,api_key]  # Creates a new site with args: name, api_url (must be http(s)://api.something.com/v1/ - note the ending slash), api_key

$ bin/rake add_new_site['sample','sample.com','addasdsd']
rake aborted!
Don't know how to build task 'enviroment'

Tasks: TOP => add_new_site
(See full trace by running task with --trace)

我好像遇到了不同的错误?

您打错了:enviroment 而不是 environment

这就是您收到此错误的原因:

rake aborted!
Don't know how to build task 'enviroment'