[英]Uninitialized constant RAILS_ROOT: Surveyor gem and using Rails.root
[英]NameError: uninitialized constant Person::RAILS_ROOT
在'lib / tasks / admin.rake'中:
require 'rake'
namespace :admin do
desc "TODO"
task fake_people: :environment do
print "How many fake people do you want?"
Person.all.each do |p|
print p.first_name + ' ' + p.last_name + '********'
end
end
end
在Person.rb(model)
:
require 'rake'
class Person < ActiveRecord::Base
def admin
load File.join(RAILS_ROOT, 'lib', 'tasks', 'admin.rake')
Rake::Task["admin:fake_people"].invoke
end
end
我如何在模型中調用call_rake
中的admin:fake_people
。請幫助我,我已經失去了一整天。
嘗試:
Rails.root
因為你可能有RoR 4. RAILS_ROOT在RoR 2或3中運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.