加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 设计sign_in_and_redirect似乎永远不会起作用

发布时间:2020-12-16 19:04:50 所属栏目:百科 来源:网络整理
导读:我想,如果在用户登录后,它会自动重定向到以前的位置,但这似乎永远不会发生,它总是会重定向回根位置.从阅读有关设计的文档看来,这个功能似乎只是起作用.我是以某种方式错误地使用它和/或我如何强制它存储位置和重定向无论如何? http://rubydoc.info/github/p
我想,如果在用户登录后,它会自动重定向到以前的位置,但这似乎永远不会发生,它总是会重定向回根位置.从阅读有关设计的文档看来,这个功能似乎只是起作用.我是以某种方式错误地使用它和/或我如何强制它存储位置和重定向无论如何?

http://rubydoc.info/github/plataformatec/devise/master/Devise/Controllers/Helpers#stored_location_for-instance_method

authentication = UserToken.find_by_provider_and_uid(omniauth['provider'],omniauth['uid'])

if authentication
  flash[:notice] = I18n.t "devise.omniauth_callbacks.success",:kind => omniauth['provider']
  sign_in_and_redirect(:user,authentication.user)
else

解决方法

滚动到 this Google group page的底部并查看被覆盖的’stored_location_for’设计方法.我的application_controller中有一个改编版本,如下所示:
def stored_location_for(resource)
    if current_user && params[:redirect_to]
      flash[:notice] = "Congratulations,you're signed up!"
      return params[:redirect_to]
    end
    super( resource ) 
  end

这应该让你通过传入’redirect_to’参数手动创建位置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读