Rails 5.1 Routes: dynamic :action parameters

前端 未结 3 1681
后悔当初
后悔当初 2021-02-05 09:45

Rails 5.0.0.beta4 introduced a deprecation warning on routes containing dynamic :action and :controller segments:

DEPRECATION WARNING: Using a dynamic :action s         


        
相关标签:
3条回答
  • 2021-02-05 10:12

    It works like this:

    get 'stripe(/:action)', controller: 'stripe', action: :action, as: "stripe"
    
    0 讨论(0)
  • 2021-02-05 10:20

    Though it's a bit cumbersome, the best approach seems to be to explicitly define the routes:

    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
    
    0 讨论(0)
  • 2021-02-05 10:26

    Is not the same case as you, but I did this:

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

    Routes:

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

    I suppose if I want a nested path I will use *:

    get '*path', to: 'pages#index'
    
    0 讨论(0)
提交回复
热议问题