【发布时间】:2016-05-03 15:48:36
【问题描述】:
Rails 5.0.0.beta4 对包含动态 :action 和 :controller 段的路由引入了弃用警告:
DEPRECATION WARNING: Using a dynamic :action segment in a route is deprecated and will be removed in Rails 5.1.
The commit message from this PR 状态:
允许通过路径指定 :controller 和 :action 值 在 config/routes.rb 中是许多问题的根本原因 在导致安全发布的 Rails 中。有鉴于此 最好将控制器和操作明确列入白名单 而不是试图将“坏”值列入黑名单或清理。
您将如何将一组操作参数“列入白名单”?我的路由文件中有以下内容,它们会引发弃用警告:
namespace :integrations do
get 'stripe(/:action)', controller: 'stripe', as: "stripe"
post 'stripe/deactivate', controller: 'stripe', action: 'deactivate'
end
【问题讨论】:
-
显而易见的答案似乎是明确定义每个动作,但这在具有许多自定义动作的控制器中似乎很麻烦。也许这是最好的做法,n'est-ce pas?
标签: ruby-on-rails-5