2

I have a weird problem. In development this problem does not exist, but in production rake throws this error message at me "uninitialized constant Program"

The "Program" is an active record model, and it's there, it's in the schema file and it's in the app/model folder.

I execute it like this rake import:xml RAILS_ENV=production. What could be the problem? Below is the full stack trace

rake import:xml RAILS_ENV=production --trace
(in /usr/mobloom/www/htdocs/remindertest)
** Invoke import:xml (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute import:xml
rake aborted!
uninitialized constant Program
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
/usr/mobloom/www/htdocs/remindertest/lib/tasks/import_assets.rake:18
/usr/mobloom/www/htdocs/remindertest/lib/tasks/import_assets.rake:9:in `each'
/usr/mobloom/www/htdocs/remindertest/lib/tasks/import_assets.rake:9
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

Line 18: program = Program.find(:first, :conditions => ['programident = ?', broadcast['PROGRAMME']['PROGRAMME_ID']])

kristian nissen
  • 2,809
  • 5
  • 44
  • 68

2 Answers2

5

Try

require 'app/models/program'

or if you need most of your models

Rails.application.eager_load!

Rake doesn't eager load your models.

See a good explanation here Rails 3 rake task can't find model in production

Community
  • 1
  • 1
David
  • 4,080
  • 1
  • 26
  • 34
-1

You've probably forgotten to depend your task on :environment.

task :xml => :environment do
  ...code here...
end

EDITED! Probably not the right answer look at the answer with the eager loading.

Aditya Sanghi
  • 13,370
  • 2
  • 44
  • 50