【发布时间】:2022-08-11 03:43:26
【问题描述】:
在启动 Rails 服务器时,我收到以下错误,任何人都可以帮助我解决这个问题。
=> 引导彪马
=> Rails 7.0.2.2 应用程序开始开发
=> 运行bin/rails server --help 以获得更多启动选项
退出
C:/Users/anmoljain01/waroong-master/config/initializers/stripe.rb:2:in <main>\': undefined method []\' for nil:NilClass (NoMethodError)
:publishable_key => Rails.application.credentials.stripe[:stripe_publishable_key],
^^^^^^^^^^^^^^^^^^^^^^^^^
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in load\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in load\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/engine.rb:667:in block in load_config_initializer\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.2/lib/active_support/notifications.rb:208:in instrument\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/engine.rb:666:in load_config_initializer\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/engine.rb:620:in block (2 个级别) in class:Engine\ '
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/engine.rb:619:in each\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/engine.rb:619:in block in class:Engine\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in instance_exec\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in run\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:61:in block in run_initializers\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:228:in block in tsort_each\'
来自 C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:422:in block (2 个级别) in each_strongly_connected_component_from\'
来自 C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:431:in each_strongly_connected_component_from\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:421:in block in each_strongly_connected_component_from\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:50:in each\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:50:in tsort_each_child\'
来自 C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:415:in call\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:415:in each_strongly_connected_component_from\'
来自 C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:349:in block in each_strongly_connected_component\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in each\'
来自 C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in call\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in each_strongly_connected_component\'
来自 C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:226:in tsort_each\' from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:205:in tsort_each\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:60:in run_initializers\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/application.rb:372:in initialize!\'
来自 C:/Users/anmoljain01/waroong-master/config/environment.rb:5:in <main>\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in require\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:42:in require_relative\' from config.ru:3:in block in \'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in eval\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in new_from_string\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:105:in load_file\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:66:in parse_file\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:349:in build_app_and_options_from_config\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:249:in app\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:422:in wrapped_app\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:76:in log_to_stdout\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:36:in start\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:143:in block in perform\'
来自内部:内核:90:in tap\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:134:in perform\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in run\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in invoke_command\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in dispatch\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command/base.rb:87:in perform\'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command.rb:48:in invoke\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands.rb:18:in \'
来自 C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require\' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require\'
从 bin/rails:4:in `\'
这也是我的 config\\initializers\\stripe.rb
`Rails.configuration.stripe = { :publishable_key => Rails.application.credentials.stripe[:stripe_publishable_key],
:secret_key => Rails.application.credentials.stripe[:stripe_secret_key] }
Stripe.api_key = Rails.application.credentials.stripe[:stripe_secret_key]`
-
您是否确认
Rails.application.credentials.stripe设置正确?错误是说Rails.application.credentials.stripe为零,因此您不能将其用作数组(请参阅stackoverflow.com/questions/41514057/…)
标签: ruby-on-rails ruby stripe-payments