Ruby on rails Rails 3-使用OmniAuth设计-登录后重定向到/users/sign_-in
我使用Desive with omniauth在facebook上登录用户。我希望在登录到登录之前登录到他们所在的页面后重定向它们 我已经用过了Ruby on rails Rails 3-使用OmniAuth设计-登录后重定向到/users/sign_-in,ruby-on-rails,redirect,login,devise,omniauth,Ruby On Rails,Redirect,Login,Devise,Omniauth,我使用Desive with omniauth在facebook上登录用户。我希望在登录到登录之前登录到他们所在的页面后重定向它们 我已经用过了 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 s
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
skip_before_filter :store_location
在我的应用程序控制器中,并使用此代码创建了一个会话\u助手
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
为了解决被重定向到“services/”的问题,在这里我可以使用facebook和其他平台进行身份验证
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
skip_before_filter :store_location
在服务和其他控制器中,我不希望将其存储为位置
Q1我现在遇到的问题是,当我使用ajax并在模式窗口中呈现登录表单时,当用户成功登录时,它会被重定向到/users/sign\u in/。我没有用户控制器,尝试创建会话\u controller.rb并在之前添加了跳过\u。。。有,但不起作用
这是我登录的路线
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
但这只会将我重定向到根页面
我真的很感激在这方面的帮助, 你有没有考虑过提供帮助的代码<代码>信号IN和AI重定向(RealthyOrthOrthOrthRead,*ARGs)< /C>(细节可以找到)?您还可以获得
注销和重定向(资源或范围)
问题2。请尝试检查会话[:return_to]
-很可能nil
我在这里回答了这个问题
在应用程序中_controller.rb
def after_sign_in_path_for(resource_or_scope)
if request.env['omniauth.origin']
request.env['omniauth.origin']
end
end
您可以传递如下参数:
/auth/facebook?referer=/path/to/redirect
Facebook身份验证后,此参数将在
env[“omniauth.params”]
中提供给您。这个后来的答案比目前被接受的答案要好。自'11年以来,这一点有没有改变,现在似乎对我有效(即Desive确实正确重定向)对于Rails 4.2、Desive 3.2和omniauth 1.2.2也不适用