rails,如何在ajax请求完成后编写回调函数
问题描述:
我想知道在ajax请求完成后,如何/在哪里编写回调函数?rails,如何在ajax请求完成后编写回调函数
即时建立一个twitter应用程序,即时通讯尝试发送电子邮件通知后,用户点击“后续”。以下/取消关注使用ajax完成。当用户点击跟随,我有...
def follow!(other_user)
relationships.create!(followed_id: other_user.id)
end
这反过来要求
def create
@user = User.find(params[:relationship][:followed_id])
current_user.follow!(@user)
respond_to do |format|
format.html {redirect_to @user}
format.js
end
UserMailer.is_now_following(@user, current_user).deliver
end
然而,通过添加UserMailer线,它落后于我的AJAX很多。在哪里/我应该如何把电子邮件请求,而不是?我在ajax完成后想到一个回调函数,但我不知道在哪里添加它或如何。
对不起,我还是比较新的。非常感谢!
嗯,我发现,也许一个很好的方法来做到这一点是使用jQuery。我决定给后续的按钮
<%= f.submit "Follow", :class => "btn btn-large btn-primary",
:id => "follow_button"%>
ID和使用jQuery的
$("#follow_button").bind('ajax:success', function() {
});
事后发送电子邮件。但是,我真的很确定我可以如何传递变量。最终的线,我想实现将
UserMailer.is_now_following(@user, current_user).deliver
CURRENT_USER是一个函数BTW其分配/返回CURRENT_USER
如何将我做到这一点?谢谢!