我写了这段代码
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
我在部署后调用db.seed:migrate
此代码适用于我的测试环境,但不适用于开发或集成环境。 它显示了这个错误:
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
谁能告诉我这是什么问题
答案 0 :(得分:11)
使用此命令行
RAILS_ENV=development bundle exec rake db:seed
如果它不起作用,您可以发布文件的内容 /config/initializers/authentication.rb