我正在使用弹出注册(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)
我做错了什么?是职位年龄问题还是失败课程问题?