Ruby on rails rails,如何在ajax请求完成后编写回调函数

Ruby on rails rails,如何在ajax请求完成后编写回调函数,ruby-on-rails,ajax,callback,Ruby On Rails,Ajax,Callback,我想知道ajax请求完成后如何/在何处编写回调函数 我正在构建一个twitter应用程序,并试图在用户单击“关注”后发送电子邮件通知。下面是使用ajax完成的。当用户单击“跟随”时,我有 def follow!(other_user) relationships.create!(followed_id: other_user.id) end 依次呼叫 def create @user = User.find(params[:relationship][:follow

我想知道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"%>
之后再发邮件。然而,我真的很确定如何传入变量。我想要达到的最终目标是

UserMailer.is_now_following(@user, current_user).deliver
current_user是一个函数btw,它分配/返回当前_用户


我该怎么做?谢谢

这些railscasts系列非常古老,但可能会有所帮助


这些railscasts系列非常古老,但可能会有所帮助

考虑一下:

重调-

Sidekiq-

延迟作业-

考虑:

重调-

Sidekiq-

延迟工作-

UserMailer.is_now_following(@user, current_user).deliver