sign_in_and_redirect 在设计中如何工作?
How does sign_in_and_redirect in devise work?
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 获取用户的 phone 号码,因此 @user
不是有效对象(我有一个 validation
)。所以,我想将用户重定向到另一个页面,在那里我可以请求 phone 号码。
如何修改 sign_in_and_redirect @user 以将我重定向到该页面而不是根 url.
Sign_in_and_redirect 方法 uses after_sign_in_path_for method to determine where to redirect the user after sign in。
您可以 easily customize your after_sign_in_path_for method 检查 phone 是否存在,然后调用 super 或重定向到用户可以输入其 phone 号码的页面。
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 获取用户的 phone 号码,因此 @user
不是有效对象(我有一个 validation
)。所以,我想将用户重定向到另一个页面,在那里我可以请求 phone 号码。
如何修改 sign_in_and_redirect @user 以将我重定向到该页面而不是根 url.
Sign_in_and_redirect 方法 uses after_sign_in_path_for method to determine where to redirect the user after sign in。
您可以 easily customize your after_sign_in_path_for method 检查 phone 是否存在,然后调用 super 或重定向到用户可以输入其 phone 号码的页面。