为什么 Ruby 版本 2.7.1p83 和 rails 6.0.3.5 在以下 ApplicationController 代码中说 config.action_dispatch 为 nil?
Why does Ruby version 2.7.1p83 and rails 6.0.3.5 says config.action_dispatch is nil in the following ApplicationController code?
为什么 Ruby 版本 2.7.1p83 和 rails 6.0.3.5 在以下 ApplicationController 代码中说 config.action_dispatch 为 nil?
class ApplicationController < ActionController::Base
config.action_dispatch.default_headers.clear #a catch-all way
# either the above one or the below
config.action_dispatch.default_headers = { #specifically iframe
'X-Frame-Options' => 'ALLOWALL'
}
end
我的 Gemfile 内容如下:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
# Amazon Web Services SDK
gem 'aws-sdk'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
比较完整的错误信息是:
Puma caught this error: undefined method `default_headers' for nil:NilClass (NoMethodError)
/home/davysouthernboy/Dropbox/Templates/Rails/mturk_external_hit/app/controllers/application_controller.rb:2:in `<class:ApplicationController>'
/home/davysouthernboy/Dropbox/Templates/Rails/mturk_external_hit/app/controllers/application_controller.rb:1:in `<main>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actiontext-6.0.3.5/lib/action_text/engine.rb:50:in `block (2 levels) in <class:Engine>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:51:in `each'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actiontext-6.0.3.5/lib/action_text/content.rb:132:in `<main>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actiontext-6.0.3.5/lib/action_text/engine.rb:47:in `block (2 levels) in <class:Engine>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:428:in `instance_exec'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:428:in `block in make_lambda'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:200:in `block (2 levels) in halting'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:605:in `block (2 levels) in default_terminator'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:604:in `catch'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:604:in `block in default_terminator'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:201:in `block in halting'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:513:in `each'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:513:in `invoke_before'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:134:in `run_callbacks'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:119:in `complete!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:76:in `ensure in block in run!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:76:in `block in run!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:70:in `tap'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:70:in `run!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.5/lib/action_dispatch/middleware/executor.rb:12:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.5/lib/action_dispatch/middleware/static.rb:126:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.5/lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/webpacker-4.3.0/lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.0.3.5/lib/rails/engine.rb:527:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/configuration.rb:228:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/server.rb:713:in `handle_request'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/server.rb:472:in `process_client'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/server.rb:328:in `block in run'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Default headers可以配置在config/application.rb
。尝试将您的代码移出 ApplicationController
并移至 config/application.rb
。这就是您可以访问 config
对象的地方。
如果需要在控制器上下文中设置 custom headers,可以使用 response.headers
。
为什么 Ruby 版本 2.7.1p83 和 rails 6.0.3.5 在以下 ApplicationController 代码中说 config.action_dispatch 为 nil?
class ApplicationController < ActionController::Base
config.action_dispatch.default_headers.clear #a catch-all way
# either the above one or the below
config.action_dispatch.default_headers = { #specifically iframe
'X-Frame-Options' => 'ALLOWALL'
}
end
我的 Gemfile 内容如下:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
# Amazon Web Services SDK
gem 'aws-sdk'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
比较完整的错误信息是:
Puma caught this error: undefined method `default_headers' for nil:NilClass (NoMethodError)
/home/davysouthernboy/Dropbox/Templates/Rails/mturk_external_hit/app/controllers/application_controller.rb:2:in `<class:ApplicationController>'
/home/davysouthernboy/Dropbox/Templates/Rails/mturk_external_hit/app/controllers/application_controller.rb:1:in `<main>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actiontext-6.0.3.5/lib/action_text/engine.rb:50:in `block (2 levels) in <class:Engine>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:51:in `each'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actiontext-6.0.3.5/lib/action_text/content.rb:132:in `<main>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actiontext-6.0.3.5/lib/action_text/engine.rb:47:in `block (2 levels) in <class:Engine>'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:428:in `instance_exec'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:428:in `block in make_lambda'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:200:in `block (2 levels) in halting'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:605:in `block (2 levels) in default_terminator'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:604:in `catch'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:604:in `block in default_terminator'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:201:in `block in halting'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:513:in `each'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:513:in `invoke_before'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/callbacks.rb:134:in `run_callbacks'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:119:in `complete!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:76:in `ensure in block in run!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:76:in `block in run!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:70:in `tap'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.5/lib/active_support/execution_wrapper.rb:70:in `run!'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.5/lib/action_dispatch/middleware/executor.rb:12:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.5/lib/action_dispatch/middleware/static.rb:126:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.5/lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/webpacker-4.3.0/lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.0.3.5/lib/rails/engine.rb:527:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/configuration.rb:228:in `call'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/server.rb:713:in `handle_request'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/server.rb:472:in `process_client'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/server.rb:328:in `block in run'
/home/davysouthernboy/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.7/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Default headers可以配置在config/application.rb
。尝试将您的代码移出 ApplicationController
并移至 config/application.rb
。这就是您可以访问 config
对象的地方。
如果需要在控制器上下文中设置 custom headers,可以使用 response.headers
。