3

我写了这段代码

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

谁能告诉我有什么问题

4

1 回答 1

12

使用此命令行

RAILS_ENV=development bundle exec rake db:seed

如果它不起作用,您可以发布文件/config/initializers/authentication.rb的内容

于 2013-04-11T09:09:47.870 回答