DEPRECATION WARNING: Using a dynamic :controller s

2019-07-31 10:00发布

问题:

I have config/routes.rb with warning

DEPRECATION WARNING: Using a dynamic :controller segment in a route is deprecated and will be removed in Rails 5.1.

Don't know how to rewrite to remove the warning. Any document to understand how todo. Or new code Thx.

Rails.application.routes.draw do
  post ':controller(/:action(/:id))(.:format)'
  get ':controller(/:action(/:id))(.:format)'
  get '/logout' => 'sessions#destroy', :as => 'logout'
  get '/auth/failure' => 'sessions#failure'
  post '/auth/:provider/callback' => 'sessions#create'
  resources :sessions
  resources :identities
  root :to => 'myapp#index'
end

回答1:

Here what I did. Loop all get, It's feel like go back to hard code. But I don't know if any way better, So far work with Rails 5.2 beta

Rails.application.routes.draw do
  mount Ckeditor::Engine => '/ckeditor'
  post '/auth/:provider/callback' => 'sessions#create'
  get '/auth/:provider/callback' => 'sessions#create'
  get '/logout' => 'sessions#destroy', :as => 'logout'
  jinda_methods = ['pending','status','search','doc','logs','ajax_notice']
  jinda_methods += ['init','run','run_do','run_form','end_form']
  jinda_methods.each do |aktion| get "/jinda/#{aktion}" => "jinda##{aktion}" end
  post '/jinda/pending' => 'jinda#index'
  post '/jinda/end_form' => 'jinda#end_form'
  get '/articles/my' => 'articles/my'
  resources :articles
  resources :identities
  resources :sessions
  resources :password_resets
  resources :jinda, :only => [:index, :new]
  root :to => 'jinda#index'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end