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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:18:41+00:00 2026-05-26T23:18:41+00:00

The HTML form: <form id=newsletter method=post action=/subscribers data-remote=true> <label for=email>Enter your email:</label> <input type=text

  • 0

The HTML form:

<form id="newsletter" method="post" action="/subscribers" data-remote="true">
    <label for="email">Enter your email:</label>
    <input type="text" name="email" class="text" />
    <p class="btn"><span>Signup</span></p>
</form>

Note the data-remote="true"

The Controller:

class SubscribersController < ApplicationController
  def create
    @subscriber = Subscriber.create(:email      => params[:email],
                                    :ip_address => request.remote_ip )

    respond_to do |format|
      format.js
    end
  end
end

The View (subscribers/create.js.erb)

no clue what goes here to make it return normal AJAX response (or error if it encountered one

1. What do i put in the view to make it return normal ajax response or error? — Is it even needed to begin with (can I return this without creating such views)

2. Is this the correct way of doing ajax with Rails?

  • 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-05-26T23:18:41+00:00Added an answer on May 26, 2026 at 11:18 pm

    This looks exactly like a question that I just answered today for another user… same model names and everything.

    def create
      @subscriber = Subscriber.new(#your params)
      respond_to do |format|
        if @subscriber.save
          format.js { render :json => @subscriber, :status => :created, :location => @susbscriber }
        else
          format.js { render :json => @susbcriber.errors, :status => :unprocessable_entity }
        end
      end
    end
    

    Also, you shouldn’t have to do the unless Subscriber.find_by_email(params[:email]) in your controller. You should just add validates_uniqueness_of :email to the Subscriber model.

    In the .erb file that contains the form, you would add the following javascript:

    jQuery(function($) {
      // create a convenient toggleLoading function
      var toggleLoading = function() { $("#loading").toggle() };
    
      $("#your-form")
        .bind("ajax:loading",  toggleLoading)
        .bind("ajax:complete", toggleLoading)
        .bind("ajax:success", function(event, data, status, xhr) {
          $("#response").html(data);
        });
        .bind("ajax:failure", function(event, data, status, xhr) {
          //your code
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My HTML FORM code: <form action=upload.php method=GET enctyped=multipart/form-data> <label for=file> Filename:</label> <input type=file name=loadedFile
html form <form action=upload.php method=POST enctype=multipart/form-data> <input type=file name=file /><p /><input type=submit value=Uplaod />
My html form is: <div id=account-box> <form method=post> <label for=username>Username:&nbsp;<span class=input-bg><input class=login-input name=loginUser type=text
My HTML form is something like as follows <form id=form1 name=form1 method=post action=> number:
Situation : An html form (with the method=POST and enctype=multipart/form-data attributes set properly) is
In an HTML form post what are valid characters for creating a multipart boundary?
I am implementing an HTML form with some checkbox input elements, and I want
I have an HTML form - with PHP, I am sending the data of
I have a HTML form, and I have a Controller Action that accepts the
When I create a html form like this: $form = new Zend_Form(); $form->setMethod('post'); $form2->addElement('textarea',

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.