例如,如果邮件程序send_signup_mail
很重并且需要一段时间才能完成,我如何才能sign_in_and_redirect
先执行并在视图呈现后在后台发送邮件。
在下面的代码中,这只需要以线性顺序执行,但我认为这不是实际发生的事情,因为重定向直到邮件发送后才会完成。
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@fb_response = request.env["omniauth.auth"]
@user = User.from_omniauth(@fb_response)
if @user.persisted?
# Update user token
@user.fb_token = @fb_response.credentials.token
# Sign in
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?
# Deliver signup mail
UserNotifier.send_signup_email(@user).deliver
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
谢谢!