如果登录失败,则无法取消重定向(设计宝石)

时间:2012-07-26 08:00:14

标签: ruby-on-rails devise override

我正在使用弹出式注册(usign Bootstrap),如果用户无法登录,则需要取消重定向。

我尝试使用本教程 - http://casperfabricius.com/site/2010/09/30/ajax-sign-in-and-sign-up-with-devise/,但失败了。

我认为我的问题 - CustomFailure类没有覆盖标准类。

我有会话控制器:

 class SessionsController < Devise::SessionsController

 def sign_in_and_redirect(resource_or_scope, resource=nil)
   scope = Devise::Mapping.find_scope!(resource_or_scope)
   resource ||= resource_or_scope
   redirect_url = stored_location_for(scope)
   respond_to do |format|
   format.js do
    sign_in(scope, resource) unless warden.user(scope) == resource
    if redirect_url.present?
      redirect_url = "#{redirect_url}.js" unless redirect_url[-3..-1] == '.js'
      redirect_url += redirect_url.match(/\?/) ? '&' : '?'
      redirect_url += "after_authentication=true"
      redirect_to redirect_url
    else
      render(:update) do |page|
        page << render('/shared/after_authentication')
      end
    end
    end
    format.html { super }
   end
  end
 end

在我的routes.rb中:

devise_for :users, :controllers => {:registrations => 'registrations', :sessions => 'sessions'}

我在lib文件夹中创建了custom_failure.rb文件:

   class CustomFailure < Devise::FailureApp
    # Never do http authentication through Devise
   def http_auth?
     false
    end
    def redirect_url
     send(:"new_#{scope}_session_path", :format => (request.xhr? ? 'js' : nil ))
    end
   end

最后在我的devise.rb中:

       require 'custom_failure'
       config.warden do |manager|
         manager.failure_app = CustomFailure
       end

添加到我的application.rb“

      config.autoload_paths += %W(#{config.root}/lib)

我做错了什么?在岗位年龄或失败类中是否有问题?

0 个答案:

没有答案