我的rake任务找不到模型来自生产环境中的宝石,但是可以用于开发。
我经常阅读这个主题(还有很多其他人): Rails 3 rake task can't find model in production
但我无法解决问题。
Rake在app / models上发现我的其他课程没有任何问题。它只错过了来自宝石“rapns”的'RapnsNotification'。此类在场景中加载。
这是我的任务:
require "rubygems"
require "active_record"
require "awesome_print"
require 'rake'
require 'rapns'
task :delete_user => :environment do |t, args|
print "Deleting completely user..."
print Rails.root
user_id = ENV["id"]
@user = User.find(user_id)
STDOUT.puts "Do you really want to delete #{@user.firstname} #{@user.lastname} (#{@user.email})? (y/n)"
input = STDIN.gets.strip
if input == 'y'
DeleteUserScenario.call!(@user) unless @user.nil?
else
print "deleting user stopped"
end
end
这是我所做的命令(如果有帮助的话):
RAILS_ENV=devcenter bundle exec rake delete_user id=111
这是我的错误:
rake aborted!
uninitialized constant Notification::RapnsNotification
...bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/inheritance.rb:111:in `compute_type'
...bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/reflection.rb:172:in `klass'
提前谢谢你。