Rails Rails 配置的问题,请指教

qq2729877005 · 2018年07月02日 · 最后由 qq2729877005 回复于 2018年07月02日 · 368 次阅读
Rails.application.config.action_controller.raise_on_unfiltered_parameters = true

这个配置位于 config/initializers/new_framework_defaults.rb 文件,默认值是 true,但启动服务后访问应用报错(如下),改为 false 才正常,这个配置具体作用是干什么的?有没有文档提供一下?为什么会出现这种错误?我使用的 Rails 版本是 5.0.0.1,Ruby 版本是 2.3.7。

2018-07-02 12:09:01 +0800: Rack app error: #<RuntimeError: Invalid option key: raise_on_unfiltered_parameters=>
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/railtie.rb:59:in `block (3 levels) in <class:Railtie>'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/railtie.rb:54:in `each'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/railtie.rb:54:in `block (2 levels) in <class:Railtie>'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/base.rb:263:in `<class:Base>'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/base.rb:164:in `<module:ActionController>'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/base.rb:5:in `<top (required)>'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/static.rb:77:in `ext'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/static.rb:33:in `match?'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/static.rb:130:in `call'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:522:in `call'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/puma-3.4.0/lib/puma/configuration.rb:224:in `call'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/puma-3.4.0/lib/puma/server.rb:569:in `handle_request'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/puma-3.4.0/lib/puma/server.rb:406:in `process_client'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/puma-3.4.0/lib/puma/server.rb:271:in `block in run'
/home/ouge/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/puma-3.4.0/lib/puma/thread_pool.rb:114:in `block in spawn_thread'
共收到 2 条回复
early 回复

谢谢,看了文档后,我调试了一下,还是不怎么理解

文档说明

# make hash conversion of the parameters raise an error if they are not permitted.
config.action_controller.raise_on_unfiltered_parameters

调试内容

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册