RoR链接打破生产而不是开发

时间:2018-05-21 20:18:44

标签: ruby-on-rails

我有一些破坏的链接。一,我使用delete方法的注销,返回此错误:

[Devise] Could not find devise mapping for path "/users/sign_out". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]

我的路线中有这个:get '/users/sign_out', to: 'devise/sessions#destroy'

我的设计路线如下:

devise_for :users, controllers: { sessions: 'sessions',
                                    registrations: 'registrations',
                                    invitations: 'invitations' }

为什么会这样?

1 个答案:

答案 0 :(得分:0)

I have this in my routes: get '/users/sign_out', to: 'devise/sessions#destroy'

如果您想允许用户通过GET方法退出,您只需转到app/config/initializers/devise.rb并取消注释config.sign_out_via = :get

或试试这个

devise_scope :user do
  get '/users/sign_out', to: 'devise/sessions#destroy'
end