Rails 3 - 使用 OmniAuth 设计 - 登录后重定向到/users/sign_in [英] Rails 3 - Devise With OmniAuth - Redirect after signing in goes to /users/sign_in

查看:39
本文介绍了Rails 3 - 使用 OmniAuth 设计 - 登录后重定向到/users/sign_in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 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

在我的应用程序控制器中,并使用此代码制作了一个 session_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

并解决被重定向到services/"的问题,在那里我有使用 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 并在模式窗口中呈现登录表单时,当用户成功登录时,它会被重定向到/users/sign_in/.我没有用户控制器并尝试制作一个 session_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.

这是我的登录路径

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 我尝试在用户退出时使用重定向

Q2 I've tried to use the redirect when users sign out

  def after_sign_out_path_for(resource_or_scope)
      (session[:return_to].nil?) ? "/" : session[:return_to].to_s
  end

但这只会将我重定向到根页面.

But that only redirects me to the root page.

我非常感谢您对此的任何帮助

I really appreciate any help in this,

推荐答案

我在这里回答了这个问题

I answered this here

设计没有正确重定向到使用 facebook 等 omniauth 提供程序时存储的位置

在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆