设备中的sign_in_and_redirect如何工作?

2023-12-21

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)。因此,我想将用户重定向到另一个页面,我可以在其中询问电话号码。

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


Sign_in_and_redirect 方法uses after_sign_in_path_for确定登录后将用户重定向到何处的方法 https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb#L236.

You can 轻松定制您的after_sign_in_path_for method https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb#L184-L213检查电话是否存在,然后致电 super 或重定向到用户可以输入电话号码的页面。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

设备中的sign_in_and_redirect如何工作? 的相关文章

随机推荐