【问题标题】:Why doesn't it know how to build this task?为什么它不知道如何构建这个任务?
【发布时间】:2015-01-30 08:20:00
【问题描述】:

所以我在 jruby 上运行的 rails 中有以下任务:

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)

我似乎遇到了另一个错误?

【问题讨论】:

  • 不,因为如果你这样做,那么它会将 add、sample 和 sample.com 作为三个独立的 rake 任务运行。
  • 你说的很对,很抱歉浪费时间,我会删除我的评论:)
  • 你能给出bin/rake -T的(相关)输出吗?

标签: ruby-on-rails rake rake-task rakefile


【解决方案1】:

你有一个错字:enviroment 而不是environment

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

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

【讨论】:

    猜你喜欢
    • 2013-02-01
    • 2016-01-20
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    相关资源
    最近更新 更多