gpt4 book ai didi

ruby-on-rails-5 - Rails 5.1 路由 : dynamic :action parameters

转载 作者:行者123 更新时间:2023-12-03 20:22:43 26 4
gpt4 key购买 nike

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状态:

Allowing :controller and :action values to be specified via the path in config/routes.rb has been an underlying cause of a number of issues in Rails that have resulted in security releases. In light of this it's better that controllers and actions are explicitly whitelisted rather than trying to blacklist or sanitize 'bad' values.



您将如何将一组操作参数“列入白名单”?我的路由文件中有以下内容,它们会引发弃用警告:
namespace :integrations do
get 'stripe(/:action)', controller: 'stripe', as: "stripe"
post 'stripe/deactivate', controller: 'stripe', action: 'deactivate'
end

最佳答案

虽然有点麻烦,但最好的方法似乎是明确定义路线:

namespace :integrations do
namespace 'stripe' do
%w(auth webhook activate).each do |action|
get action, action: action
end
end
post 'stripe/deactivate', controller: 'stripe', action: 'deactivate'
end

关于ruby-on-rails-5 - Rails 5.1 路由 : dynamic :action parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37008713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com