简体   繁体   English

Rails 3 with Devise:没有路由匹配/ d / users / sign_out

[英]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. 我搜索了谷歌,但仍然感到难过。

Update: 更新:

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. 抱歉,它很小,但你可以右键单击然后自己查看它以获得更大的屏幕。

在此输入图像描述

Update #2: 更新#2:

The jquery_ujs file is included. 包含jquery_ujs文件。

Update #3: 更新#3:

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 ...不确定如何解决这个问题。

Update #4: 更新#4:

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.

相关问题 Rails设计错误“没有路由匹配[GET]”/ users / sign_out“” - Rails Devise Error “No route matches [GET] ”/users/sign_out“” Rails 3 Devise-获取“没有路线匹配” / users / sign_out“” - Rails 3 Devise - Getting “ No route matches ”/users/sign_out“ ” 设备-没有路线与[GET]“ / users / sign_out”匹配-Rails 4 - DEVISE - No route matches [GET] “/users/sign_out” - Rails 4 没有路线匹配“/users/sign_out” devise rails 3 - No route matches "/users/sign_out" devise rails 3 设计/Rails:没有路由匹配 [GET] “/users/sign_out” - Devise/Rails: No route matches [GET] “/users/sign_out” 无法使用Devise gem在Rails应用中注销,没有路线与/ users / sign_out匹配 - Unable to sign out in a Rails app, using Devise gem, no route matches /users/sign_out 设计没有路线匹配[GET]“/ users / sign_out” - devise No route matches [GET] “/users/sign_out” 设计路由错误:没有路由与[GET]“ / users / sign_out”匹配 - Devise routing error: No route matches [GET] “/users/sign_out” 在Rails 3.1中设计路线问题,没有路线匹配[GET]“ / users / sign_out” - Devise routes issue in Rails 3.1 with No route matches [GET] “/users/sign_out” Rails Devise,没有路由匹配&#39;/users/sign_out&#39; -&gt; SignOut/Logout Routes 问题 - Rails Devise, No route matches '/users/sign_out' -> SignOut/Logout Routes problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM