Rake Work Tasks Don't Recognize My Models

When I launched Heroku Bamboo, it was never a problem. Now, at Cedar, I get errors whenever I try to access my models due to a rake task on the server. This happens with rake db:seed , the standard rake task, as well as my own custom tasks that explicitly include: environment. I even do this in excess:

 namespace :db do desc "Update db" task :new_seed => :environment do require './Scraped_Data/Games/code/column-headers.rb' require 'csv' require 'net/http' require './config/environment.rb' # code here... end end 

I can’t find any mention of this problem elsewhere, and all of these tasks work great in development. Thanks for any ideas, and here is the complete error message message that pulls out as soon as they run into my Heroku model:

 rake aborted! uninitialized constant Object::Movie /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing' /app/lib/tasks/new_seed.rake:187:in `block in load_scraped_data' /app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open' /app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open' /app/lib/tasks/new_seed.rake:148:in `load_scraped_data' /app/lib/tasks/new_seed.rake:550:in `block (2 levels) in <top (required)>' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' /app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' /app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load' /app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>' Tasks: TOP => db:new_seed 
+7
source share
2 answers

Default threadafe set dependency_loading = false
If you want to enable thread safety in your application and access your models in your task, you need to download it.

 # Enable threaded mode config.threadsafe! config.dependency_loading = true if $rails_rake_task 


Ref .: http://nowhereman.github.com/how-to/rails_thread_safe/

Hope this help!

+20
source

I had threadsafe! = true threadsafe! = true configured in my working environment config/environments/production.rb

Disabling this solution fixes the problem.

The answer is: rake aborted! uninitialized constant Object :: Country, why can't I see the model? gives some additional explanations and other workarounds (in particular, the last link)

+1
source

All Articles