【问题标题】:DEPRECATION WARNING: Using a dynamic :controller segment in a route is deprecated and will be removed in Rails 5.1弃用警告:在路由中使用动态 :controller 段已被弃用,并将在 Rails 5.1 中删除
【发布时间】:2017-02-12 16:00:53
【问题描述】:

我有带有警告的 config/routes.rb

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

不知道如何重写以删除警告。 任何了解如何做的文件。或新代码 谢谢。

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

【问题讨论】:

  • 对“post ':controller(/:action(/:id))(.:format)' 的新重写得到 ':controller(/:action(/:id))(. :format)' "?
  • 在我看来,从网上冲浪来看,动态动作/控制器已被淘汰,别无选择。我想这与应用程序的安全性有关。到目前为止,我发现的最佳解决方案是将所有操作列入白名单,从而将它们全部写出来,或循环遍历它们,如重复问题的答案所示。
  • 并且:github.com/rails/rails/issues/27231,@TheR2(在问题中)有一个针对:action 的解决方法,通过一些搜索也许这也可以针对:controller 完成。

标签: routes ruby-on-rails-5


【解决方案1】:

这就是我所做的。 循环全部获取,感觉就像回到硬代码。 但我不知道是否有更好的方法,到目前为止使用 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

【讨论】:

    猜你喜欢
    • 2017-05-25
    • 2017-08-02
    • 2016-12-07
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-07-02
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多