代码之家  ›  专栏  ›  技术社区  ›  Travis Pessetto

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

  •  6
  • Travis Pessetto  · 技术社区  · 13 年前

    当我试图注销设计错误时,出现以下错误:

    没有与[GET]“/d/users/sign_out”匹配的路由

    我的标签是正确的,如下所示:

    <%= link_to "Sign Out", destroy_session_path, :method=>:delete %>
    

    我的设计路线是:

    devise_for :users, :path_prefix=>"d", :controllers=>{:sessions=>"sessions"}
    

    其他路线包括:

    resources :users#For CRUD defined after devise_for like in Devise Wiki
    

    使用自定义控制器会话进行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
    

    设计初始值设定项具有:

    config.sign_out_via = :delete
    

    有什么想法可以引起这个问题吗?我在谷歌上搜索过,但仍然被难住了。

    更新:

    下面是为设备用户提供的rails路由文件的屏幕截图。抱歉,它很小,但您可以右键单击,然后单独查看它以获得更大的屏幕。

    enter image description here

    更新#2:

    其中包括jquery_ujs文件。

    更新#3:

    控制台中显示,删除确实正在传递,但它正在从session_controller跳到d/users/sign_out。。。不知道如何解决这个问题。

    更新#4:

    当重定向时,它首先作为DELETE转到d/users/sign_out,这是应该的。然后重定向到 root_url 然后给出错误 ERROR Errno::ECONNABORTED: An established connection was aborted by the software in your host machine. 然后,它尝试重定向到d/users/sign_out作为GET,在那里它失败了。

    3 回复  |  直到 5 年前
        1
  •  4
  •   Travis Pessetto    13 年前

    这似乎是Devise和Ruby 1.9.2-p290之间的问题。更新到Ruby 1.9.3并运行 bundle update 以确保使用最新版本的Devise;似乎有效。

        2
  •  1
  •   Justin Soliz    13 年前

    听起来你可能已经删除了 //= require jquery_ujs 从您的application.js文件。我认为处理链接细节是为了提出“删除”请求。无论哪种方式,就像现在一样,你正在进行一次“获取”,这显然不会影响你的 destroy_user_session 方法

        3
  •  1
  •   Community Mohan Dere    8 年前

    更改:

    config.sign_out_via = :delete
    

    收件人:

    config.sign_out_via = :get
    

    请参阅相关内容:

    No route matches "/users/sign_out" devise rails 3