2016-11-20 68 views
0

我曾經在cmd行執行rails test,或者rails db:migrate RAILS_ENV=test我一直在爲我的omniauth initialzer收到一個NoMethodError,儘管rails服務器工作正常,在我的heroku站點上,我的代碼中的omniauth被推到。我讀了Rails: Per-environment initializers?這個問題,並在我的omniauth initialzer文件的頂部添加了if Rails.env.production?,所以爲了生產而運行omniauth initialzer,但我沒有運氣。在開發環境軌道上跳過初始化程序

完整的錯誤是;

db:migrate RAILS_ENV=test --trace 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
rails aborted! 
NoMethodError: undefined method `[]' for nil:NilClass 
C:/Sites/Peoples_Profiles/config/initializers/omniauth.rb:5:in `block in <top (required)>' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/omniauth-1.3.1/lib/omniauth/builder.rb:6:in `initialize' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:35:in `new' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:35:in `build' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `block in build' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `inject' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:100:in `build' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/engine.rb:508:in `block in app' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/engine.rb:504:in `synchronize' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/engine.rb:504:in `app' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:37:in `block in <module:Finisher>' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `call' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!' 
C:/Sites/Peoples_Profiles/config/environment.rb:5:in `<top (required)>' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/application.rb:328:in `require_environment!' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `call' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:209:in `block in invoke_prerequisites' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:207:in `each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:207:in `invoke_prerequisites' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:186:in `block in invoke_with_call_chain' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:152:in `invoke_task' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `each' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block in top_level' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:117:in `run_with_threads' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:102:in `top_level' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:10:in `run_rake_task' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:51:in `run_command!' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>' 
bin/rails:4:in `require' 
bin/rails:4:in `<main>' 
Tasks: TOP => db:migrate => environment 

任何人有任何想法,爲什麼這是?

回答

0

如果Rails.env.production被添加?在我的omniauth initialzer文件的頂部

只要將它添加到頂部將無所作爲。 包裝你的條件的邏輯

if Rails.env.production? 
    # your omniauth stuff 
end 
+0

ahh謝謝你。對不起還在學習:) –