LoginSignup
1
3

More than 5 years have passed since last update.

[Rails5] Rails5.1以降でraise_on_unfiltered_parameters関連のエラーが発生してページ表示されない

Last updated at Posted at 2018-05-20

発生したこと

Rails 5.2.0でウェルカムページを表示するだけの初期段階で、5.0までの頃にはなかった以下エラーが出力。
以下のエラーと同じ内容がブラウザに表示される事象です。

ターミナル
twitter $ bundle e rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
2018-05-20 19:00:02 +0900: Rack app error handling request { GET / }
#<RuntimeError: Invalid option key: raise_on_unfiltered_parameters=>
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_controller/railtie.rb:63:in `block (3 levels) in <class:Railtie>'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_controller/railtie.rb:58:in `each'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_controller/railtie.rb:58:in `block (2 levels) in <class:Railtie>'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `each'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_controller/base.rb:274:in `<class:Base>'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_controller/base.rb:166:in `<module:ActionController>'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_controller/base.rb:7:in `<top (required)>'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:79:in `ext'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:35:in `match?'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:121:in `call'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/engine.rb:524:in `call'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

暫定対策

一旦、Rails 5.1から追加された以下設定をコメントアウトすることで対応しました。
ちなみに、値をfalseにしても効果はありませんでした。

config/initializers/new_framework_defaults.rb
Rails.application.config.action_controller.raise_on_unfiltered_parameters = true

本対策

調査中

エラー発生箇所

rails/actionpack/lib/action_controller/railtie.rb
53:      ActiveSupport.on_load(:action_controller) do
54:        include app.routes.mounted_helpers
55:        extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
56:        extend ::ActionController::Railties::Helpers
57:
58:        options.each do |k, v|
59:          k = "#{k}="
60:          if respond_to?(k)
61:            send(k, v)
62:          elsif !Base.respond_to?(k)
63:            raise "Invalid option key: #{k}"
64:          end
65:        end
66:      end

railtie.rbの62行目にて、raise_on_unfiltered_parameters=なるメソッドが存在しないことが直接原因と想定。

考察

暫定対策でコメントアウトしたパラメータ名のとおり、生のパラメータだと受け付けないことになっている?
リクエストパラメータを確認したところ、何も処理していないのでpermitted: falseになっているところが怪しい。

ターミナル
pry> params
=> <ActionController::Parameters {"controller"=>"welcome", "action"=>"index"} permitted: false>

原因が判明次第、追記したいと思います。

1
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3