在开发环境中跳过初始化程序

时间:2016-11-20 08:48:22

标签: ruby-on-rails ruby ruby-on-rails-5

什么时候,我在cmd行中执行rails test,或者rails db:migrate RAILS_ENV=test我的omniauth初始化器仍然没有得到NoM​​ethodError,虽然rails服务器工作正常,omniauth在我的,heroku网站上我的代码被推送到。我读了这个问题Rails: Per-environment initializers?,并在我的omniauth初始化文件的顶部添加了if Rails.env.production?,所以只为生产运行omniauth初始化器,但我没有运气。

完整的错误是;

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

任何人都有任何想法,为什么会这样?

1 个答案:

答案 0 :(得分:0)

  

如果Rails.env.production添加?在我的omniauth初始化文件的顶部

只需将其添加到顶部即可。在条件

换行你的逻辑
https://graph.microsoft.com/v1.0/users/{my user id}/drive/root/children