设计中的sign_in_and_redirect如何工作? [英] How does sign_in_and_redirect in devise work?

查看:162
本文介绍了设计中的sign_in_and_redirect如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
end

facebook omniauth callbacks controller中存在此方法.我面临的问题是我没有从facebook获得用户的电话号码,因此@user不是有效的对象(我有一个validation).因此,我想将用户重定向到另一个页面,我可以在其中询问电话号码.

This method is present in the facebook omniauth callbacks controller. The problem that I am facing is that I do not get the user's phone number from facebook and thus @user is not a valid object (I have a validation). So, I want to redirect the user to another page where I can ask for the phone number.

如何修改sign_in_and_redirect @user以将我重定向到该页面而不是根URL.

How can I modify the sign_in_and_redirect @user to redirect me to that page and not the root url.

推荐答案

Sign_in_and_redirect方法

Sign_in_and_redirect method uses after_sign_in_path_for method to determine where to redirect the user after sign in.

您可以轻松自定义您的 after_sign_in_path_for 方法检查电话是否存在,然后调用超级方法或重定向到用户可以输入其电话号码的页面.

You can easily customize your after_sign_in_path_for method to check for the phone presence and either call super or redirect to the page where user can enter their phone number.

这篇关于设计中的sign_in_and_redirect如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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