我在 semester.rake
文件中有一个 rake 任务。看起来像这样
namespace :db do
desc "generate semester data"
task semester: :environment do
semester = Semester.create!(name: "SummerSemseter")
semester = Semester.create!(name: "WinterSemester")
semester = Semester.create!(name: "Spring Semester")
end
end
我将任务作为
rake semester
运行。这给了我错误rake aborted!
Don't know how to build task 'semester' (see --tasks)
/home/john/.rvm/gems/ruby-2.2.4/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/home/john/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
/home/john/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
为什么我会收到此错误以及解决方案是什么?
最佳答案
您的 semester
任务位于 namespace db
中。
因此,您需要使用以下命令运行它:
rake db:semester
关于ruby-on-rails - rake 中止!不知道如何构建任务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40236636/