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 8106977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:37:37+00:00 2026-06-06T00:37:37+00:00

My app has a simple signup where the user types in his/her email address

  • 0

My app has a simple signup where the user types in his/her email address and POSTs the request. The request is then sent to my server using AJAX, an email is sent to the user’s email using ActionMailer, and a thank you message is rendered using jQuery. With the code I have currently, the thank-you message is rendered only AFTER the email is sent, so it takes some time for the thank-you message to show. However, I’d like the thank-you message to be rendered first, and the email to be sent to the user in the background, so that the user can immediately know that his/her email was saved. Is there a way to process email in the background with Rails?

Below is my current code.
In users_controller.rb

def create
  @user = User.new(params[:user])

  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'Thank you for signing up!' }
      format.js
      format.json { render json: @user, status: :created, location: @user }
      Notifier.email_saved(@user).deliver
    else
      format.html { render action: "new" }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

In mailers/notifier.rb

class Notifier < ActionMailer::Base
  default from: "First Last <my@email.com>"

  def email_saved(user)
    @email = user.email
    mail to: @email, subject: 'Auto-Response: Thank you for signing up'
  end
end

In users/create.js.erb

$("<div class='alert alert-success'>Thank you for showing your interest! A confirmation email will be sent to you shortly.</div>").insertAfter("#notice");
  • 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-06T00:37:38+00:00Added an answer on June 6, 2026 at 12:37 am

    If you want to send mail only, you should use better “Resque” or “Delayed Job” than “Ajax”.

    #271 Resque – RailsCasts http://railscasts.com/episodes/271-resque

    Delayed Job (DJ) | Heroku Dev Center https://devcenter.heroku.com/articles/delayed-job

    But if you want to send mail using Ajax, please use below snippets as a reference.

    #app/controllers/users_controller.rb
    def create
      @user = User.new(params[:user])
    
      respond_to do |format|
        if @user.save
          format.html { redirect_to @user, notice: 'Thank you for signing up!', sign_up_flag: 1 }
          format.js
          format.json { render json: @user, status: :created, location: @user }
        else
          format.html { render action: "new" }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
    
    def send_mail(user_id)
        begin
          user = User.find(user_id)
          Notifier.sign_up_mail(user.email).deliver
          render :nothing => true, :status => 200
        rescue
          render :nothing => true, :status => 500
        end
    end
    
    
    
    #app/mailers/notifier.rb
    class Notifier < ActionMailer::Base
      default from: "First Last <my@email.com>"
    
      def sign_up_mail(email)
        mail to: email, subject: 'Auto-Response: Thank you for signing up'
      end
    end
    
    
    
    #app/views/???.html.erb
    <% if @sign_up_flag == 1 %>
      $(document).ready(function(){
        $.ajax({
          type: "POST",
          url:  "/sendmail",
          data: "",
          success : function(){},
          error : function() {}
        });
      });
    <% end %>
    
    
    
    #config/routes.rb
      post '/sendmail' => 'users#send_mail'
    

    Thanks.

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

Sidebar

Related Questions

I would like to build a simple beta request signup page where the user
What is the reason for deprecating startManagingCursor ? My simple app has a table
The app we're building has a simple button that starts a facetime session with
I've created a simple iPhone app which has two .xib files. In the app
I want to design simple app widget which has two textview and two button
I have a very simple Mac Cocoa app that just has a Web View
I have a simple cakephp app with table articles that has a cat_id column
I am working on a simple app tab-bar based application that has two views.
I have an iPhone app that shows a simple view (View 1) that has
I'm making a simple app. and it is my first app too... It has

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.