Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:46:42+00:00 2026-06-01T12:46:42+00:00

i was wondering how/where to write a callback function after an ajax request is

  • 0

i was wondering how/where to write a callback function after an ajax request is complete?

im building a twitter app and im trying to send an email notification after a user clicks ‘follow’. the following/unfollowing is done using ajax. when a user clicks follow, i have…

  def follow!(other_user)
    relationships.create!(followed_id: other_user.id)
  end

which in turns calls

  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

however, by adding that UserMailer line, it lags my ajax a lot. where/how should i put the email request instead? i was thinking of a callback function after the ajax is finished, but im not sure where to add it or how.

sorry i still quite new to this. thanks a lot!

hmmm, i found out that maybe a good way to do this is to use jquery. i decided to give the follow button

<%= f.submit "Follow", :class => "btn btn-large btn-primary", 
        :id => "follow_button"%>

an id and used jquery

$("#follow_button").bind('ajax:success', function() {

});

to send the email afterwards. however, im really sure how i could pass in variables. the ultimate line i want to achieve would be

UserMailer.is_now_following(@user, current_user).deliver

current_user is a function btw which assigns/returns the current_user

how would i do this? thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:46:43+00:00Added an answer on June 1, 2026 at 12:46 pm

    These railscasts series are pretty old, but may be helpful

    http://railscasts.com/episodes/127-rake-in-background

    http://railscasts.com/episodes/128-starling-and-workling

    http://railscasts.com/episodes/129-custom-daemon

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering how can I write a function: 'a list*int -> 'a list*list that
I'm just wondering if there is a best case to write this code: $('#set_duration_30').click(function(event)
Wondering why a particular binary write operation in VB is so slow. The function
I was wondering if it's possible to write a function that accepts multiple generic
I am wondering how to write μ-recursive function in any functional programming language?
I'am wondering, how to write integration tests, that involves DB interaction, for Google app
I am trying to write tests for a date helper class. I am wondering
Wondering when a write-back should be performed? I thought it was when you're writing
I was wondering how to better write code like this so that it leverages
I am wondering if it is possible to write count(vanilla) instead of vanilla.count() ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.