[英]Rails 3 with Devise: No route matches /d/users/sign_out
I am getting the following error when I try to sign out of devise error: 当我尝试退出设计错误时,我收到以下错误:
No route matches [GET] "/d/users/sign_out" 没有路线匹配[GET]“/ d / users / sign_out”
My tag is correct, it is as follows: 我的标签是正确的,如下:
<%= link_to "Sign Out", destroy_session_path, :method=>:delete %>
My route for devise is: 我的设计路线是:
devise_for :users, :path_prefix=>"d", :controllers=>{:sessions=>"sessions"}
Other routes are: 其他路线是:
resources :users#For CRUD defined after devise_for like in Devise Wiki
With a custom controller sessions for ajax login like on the Devise wiki page: 使用自定义控制器会话进行ajax登录,例如在Devise wiki页面上:
class SessionsController < Devise::SessionsController
def create
respond_to do |format|
format.html{ super }
format.json do
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
#resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
return sign_in_and_redirect(resource_name, resource)
end
end
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}
end
def failure
return render:json => {:success => false, :errors => ["Login failed."]}
end
end
The devise initializer has: 设计初始化程序具有:
config.sign_out_via = :delete
Any ideas on what could be causing the problem? 关于什么可能导致问题的任何想法? I've searched Google and am still stumped. 我搜索了谷歌,但仍然感到难过。
Here is a screenshot of the rails routes file for the devise users. 以下是设计用户的rails路径文件的屏幕截图。 Sorry, it is small, but you can right-click then view it by itself for a larger screen. 抱歉,它很小,但你可以右键单击然后自己查看它以获得更大的屏幕。
The jquery_ujs file is included. 包含jquery_ujs文件。
It appears in the console that delete is indeed being passed, but it is jumping from the sessions_controller to / then to d/users/sign_out...Not sure how to fix this. 它在控制台中显示删除确实正在传递,但是它从sessions_controller跳转到/然后转到d / users / sign_out ...不确定如何解决这个问题。
When redirecting it goes first to d/users/sign_out as DELETE, as it should. 重定向时,首先将d / users / sign_out作为DELETE传递给它。 It then redirects to root_url
which then gives the error ERROR Errno::ECONNABORTED: An established connection was aborted by the software in your host machine.
然后重定向到root_url
,然后给出错误ERROR Errno::ECONNABORTED: An established connection was aborted by the software in your host machine.
It then tries to redirect to d/users/sign_out as GET where it is failing. 然后它尝试重定向到d / users / sign_out作为GET失败的地方。
This appears to be an issue between Devise and Ruby 1.9.2-p290. 这似乎是Devise和Ruby 1.9.2-p290之间的问题。 Updating to Ruby 1.9.3 and running bundle update
to ensure the latest version of Devise was used; 更新到Ruby 1.9.3并运行bundle update
以确保使用最新版本的Devise; appears to work. 似乎工作。
It sounds like you might have removed //= require jquery_ujs
from your application.js file. 听起来你可能已经从application.js文件中删除了//= require jquery_ujs
。 I think that handles the link particulars to make a 'delete' request. 我认为处理链接细节以发出“删除”请求。 Either way, as it is now, you're making a 'GET' which obviously won't hit your destroy_user_session
method. 无论哪种方式,就像现在一样,你正在做一个'GET',显然不会命中你的destroy_user_session
方法。
Change: 更改:
config.sign_out_via = :delete
to: 至:
config.sign_out_via = :get
See this related: 看到这个相关:
No route matches "/users/sign_out" devise rails 3 没有路由匹配“/ users / sign_out”设计rails 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.