0

我的 rake 任务找不到来自生产环境中的宝石但适用于开发的模型。

我读了很多次这个话题(还有很多其他的): Rails 3 rake task can't find model in production

但我无法解决问题。

Rake 在应用程序/模型上找到我的其他课程没有任何问题。它只错过了宝石“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'

先感谢您。

4

0 回答 0