Rails 5.1路由:动态:动作参数

时间:2016-05-03 15:48:36

标签: ruby-on-rails-5

Rails 5.0.0.beta4在包含dynamic:action和:controller segments的路由上引入了弃用警告:

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

3 个答案:

答案 0 :(得分:21)

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

.target-host-item-class

答案 1 :(得分:4)

与你的情况不一样,但我这样做了:

class PagesController < ApplicationController
  def index
    render params[:path]
  end
end

路线:

get ':path', to: 'pages#index'

我想如果我想要一个嵌套路径,我将使用*

get '*path', to: 'pages#index'

答案 2 :(得分:-3)

它的工作原理如下:

get 'stripe(/:action)', controller: 'stripe', action: :action, as: "stripe"
相关问题