Using Devise in Rails 3.2.3 - Cannot sign out

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 04:02:42

问题


I am using devise 2.1.0 for my rails app 3.2.3. Here is what I did:

Add gem 'devise' to Gemfile and run bundle
Run rails g devise:install
Run rails g devise User
Setup db by running rake db:migrate

The application.html.erb is something like this:

<%if user_signed_in? %>
    Welcome <%= current_user.email%>
    <%= link_to "Sign out", destroy_user_session_path%>
<% else %>
    <%= link_to "Sign up", new_user_registration_path %> or
    <%= link_to "Sign in", new_user_session_path %> 
<% end %>

The sign in and sign up work just fine but When I click Sign out, I got an error message:

Routing Error

No route matches [GET] "/users/sign_out" Try running rake routes for more information on available routes.

Here is the output of the rake routes:

new_user_session GET    /users/sign_in(.:format)                          devise/sessions#new
            user_session POST   /users/sign_in(.:format)                          devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                         devise/sessions#destroy
           user_password POST   /users/password(.:format)                         devise/passwords#create
       new_user_password GET    /users/password/new(.:format)                     devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                    devise/passwords#edit
                         PUT    /users/password(.:format)                         devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                           devise/registrations#cancel
       user_registration POST   /users(.:format)                                  devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                          devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                             devise/registrations#edit
                         PUT    /users(.:format)                                  devise/registrations#update
                         DELETE /users(.:format)                                  devise/registrations#destroy

I am really confused as there are /usrs/sign_out routes in there. Does anyone know why?


回答1:


Try this:

<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>


来源:https://stackoverflow.com/questions/11044246/using-devise-in-rails-3-2-3-cannot-sign-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!