Rails 3 - 使用OmniAuth设计 - 登录后重定向到/ users / sign_in [英] Rails 3 - Devise With OmniAuth - Redirect after signing in goes to /users/sign_in
问题描述
我使用devise与omniauth签署Facebook用户。我希望他们在登录后登录到他们登录后的页面被重定向。
Im using devise with omniauth for signing in users with facebook. I want them to be redirected after signing in to the page they were on after before signing in.
我已经使用了
def after_sign_in_path_for(resource_or_scope)
store_location = session[:return_to]
clear_stored_location
(store_location.nil?) ? "/" : store_location.to_s
end
,并创建了一个sessions_helper使用此代码
in my application controller, and made a sessions_helper with this code
def deny_access
store_location
redirect_to new_user_session_path
end
def anyone_signed_in?
!current_user.nil?
end
private
def store_location
session[:return_to] = request.fullpath
end
def clear_stored_location
session[:return_to] = nil
end
并修复被重定向到服务/的问题,我使用Facebook和其他平台进行身份验证的逻辑我已经使用了
And to fix the problem with being redirected to "services/" where I have the logic for the authentication with facebook and other platforms I've used the
skip_before_filter :store_location
在我不被作为位置存储的服务和其他控制器中。
in services and other controllers that I don't to be stored as locations.
Q1我现在遇到的问题是当我使用ajax并在模态窗口中呈现登录表单是当用户成功登录时被重定向到/用户/ sign_in /。我没有一个用户控制器,试图使一个sessions_controller.rb,并添加了skip_before ...在那里,但它不起作用。
Q1 The problem I'm having now is when I use ajax and render a login form in a modal window is that when a user successfully signs in it gets redirected to /users/sign_in/. I don't have a user controller and tried to make a sessions_controller.rb and added the skip_before... there but it doesn't work.
这是我的路由for sign_in
This is my routes for sign_in
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
Q2当用户退出
def after_sign_out_path_for(resource_or_scope)
(session[:return_to].nil?) ? "/" : session[:return_to].to_s
end
但是只重定向我
我非常感谢任何帮助,
推荐答案
我在这里回答
在使用omniauth提供商(如Facebook)时,Devise不会正确地重定向到存储位置
在application_controller.rb中
in application_controller.rb
def after_sign_in_path_for(resource_or_scope)
if request.env['omniauth.origin']
request.env['omniauth.origin']
end
end
这篇关于Rails 3 - 使用OmniAuth设计 - 登录后重定向到/ users / sign_in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!