我正在用本教程構建一個prelaunch註冊站點。 http://railsapps.github.com/tutorial-rails-prelaunch-signup.html。在用戶輸入他們的電子郵件以請求邀請後,它使用ajax呈現_thankyou.html
部分,該部分由重寫的設計註冊控制器呈現。Rails:after_create導致ajax性能問題
但是,該網站還使用回撥after_create :send_welcome_email
發送一個歡迎'感謝請求邀請'電子郵件。這顯着降低了ajax的性能。如果沒有after_create回調,ajax(至少在本地主機上)工作速度非常快,表單很快就會消失,並且謝謝部分幾乎立即呈現。但是,如果我包含after_create回調,表單需要很長時間才能消失(這會導致用戶多次單擊提交按鈕,從而產生更多問題),謝謝部分內容也需要很長時間...
有沒有辦法安排一些東西,以便在呈現謝謝部分後觸發電子郵件?
新色器件製作方法
# ovverride #create to respond to AJAX with a partial
def create
build_resource
if resource.save
if resource.active_for_authentication?
sign_in(resource_name, resource)
(render(:partial => 'thankyou', :layout => false) && return) if request.xhr?
respond_with resource, :location => after_sign_up_path_for(resource)
else
expire_session_data_after_sign_in!
(render(:partial => 'thankyou', :layout => false) && return) if request.xhr?
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
render :action => :new, :layout => !request.xhr?
end
end
阿賈克斯觸發請求邀請提交。
// use AJAX to submit the "request invitation" form
$('#invitation_button').live('click', function() {
var email = $('form #user_email').val();
var password = $('form #user_password').val();
var dataString = 'user[email]='+ email + '&user[password]=' + password;
$.ajax({
type: "POST",
url: "/users",
data: dataString,
success: function(data) {
$('#request-invite').html(data);
}
});
return false;
});