使用Devise in Rails 3.2.3 - 无法登出 [英] Using Devise in Rails 3.2.3 - Cannot sign out
本文介绍了使用Devise in Rails 3.2.3 - 无法登出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将gem'devise'添加到Gemfile并运行bundle
运行rails g devise:install
运行rails g devise用户
通过运行rake db来设置db:migrate
application.html.erb是这样的:
<%if user_signed_in? %GT;
欢迎<%= current_user.email%>
<%= link_to退出,destroy_user_session_path%>
<%else%>
<%= link_to注册,new_user_registration_path%>或
<%= link_to登录,new_user_session_path%>
<%end%>
登录并注册工作很好,但当我点击退出时,我收到一条错误消息:
路由错误
没有路由匹配[GET]/ users / sign_out尝试运行rake路线
更多关于可用路线的信息。
这里是耙路线的输出: / p>
new_user_session GET /users/sign_in(.:format)devise / sessions#new
user_session POST / users / sign_in devise / sessions#创建
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 / passwo rd / edit(。:format)devise / passwords#edit
PUT /users/password(.:format)devise / passwords#update
cancel_user_registration GET /users/cancel(.:format)设计/注册#cancel
user_registration POST /users(.:format)设计/注册#创建
new_user_registration GET /users/sign_up(.:format)设计/注册#new
edit_user_registration GET / users / edit (。:format)设计/注册#编辑
PUT /users(.:format)设计/注册#update
DELETE /users(.:format)设计/注册#destroy
我真的很困惑,因为那里有/ usrs / sign_out路由。有没有人知道为什么?
解决方案
尝试这样:
<%= link_to退出,destroy_user_session_path,:method => :删除%>
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?
解决方案
Try this:
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
这篇关于使用Devise in Rails 3.2.3 - 无法登出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文