Unable to sign out in a Rails app, using Devise gem, no route matches /users/sign_out

前端 未结 3 1817
醉酒成梦
醉酒成梦 2021-01-25 04:13

I know there are dozens of questions on different sites about this issue. I have tried a lot of things, and I still can\'t get the link with DELETE method to work.

I\'ve

相关标签:
3条回答
  • 2021-01-25 04:28

    in devise.rb

    find config.sign_out_via = :delete

    change to config.sign_out_via = :get

    if you use :get make sure you are using :method = :get and if you are using :delete using :method => :delete in your link

    in production you may have to swap it round, so you should use an if statement to check RAILS_ENV

    In your example you are probably running in development mode and not test, which is why it's probably not working.

    And restart your server as it's an initialiser.

    0 讨论(0)
  • 2021-01-25 04:28

    This helper always works for me:

    link_to "Logout", destroy_user_session_path, :method => :delete
    

    Maybe you are not logged in properly? You could check with if current_user

    0 讨论(0)
  • 2021-01-25 04:38

    Can we see your routes file?

    Specifically the devise_for call

    You could also try setting the path explicitly

    devise_for :users, path_names: { sign_out: 'sign_out' }

    0 讨论(0)
提交回复
热议问题