我编写了这段代码
namespace :db do
task :seed, :only => {:primary => true}, :except => { :no_release => true } do
rails_env = ENV["RAILS_ENV"]
current_path = File.dirname(__FILE__)
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:seed"
end
end
在执行deploy:migrate之后,我希望你调用db.seed。
这段代码在我的测试环境中能够正常工作,但在开发或集成环境中不能正常工作。它显示以下错误:
rake aborted!
undefined method `[]' for nil:NilClass
/Users/Megha/Documents/Mckinsey project/LeanITAppServer/config/initializers/authentication.rb:6:in `<top (required)>'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `block in load'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/engine.rb:587:in `each'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/engine.rb:587:in `block in <class:Engine>'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/Megha/Documents/Mckinsey project/LeanITAppServer/config/environment.rb:6:in `<top (required)>'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/application.rb:103:in `require'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:346:in `block (2 levels) in <top (required)>'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Megha/.rvm/gems/ruby-1.9.3-p392@bto/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:abort_if_pending_migrations => environment
有人能告诉我问题出在哪里吗?