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

The Archive Base Latest Questions

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

I have a subscriber#create method that is only used for ajax submits to it

  • 0

I have a subscriber#create method that is only used for ajax submits to it (the html form uses data-remote="true" to do the Ajax. The form does indeed submit and the data ends up in the db but the method throws an error saying that the template was not found.

How can I specify a function as being an Ajax handler in Rails? — one that doesn’t have to render a template, etc.

Here is what the method looks like:

class SubscribersController < ApplicationController

  def create
    Subscriber.create(:email          => params[:email],
                      :ip_address     => request.remote_ip,
                      :referring_page => request.referer ) unless Subscriber.find_by_email(params[:email])
  end

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

    You should handle the call in your respond_to properly.

    ...
    respond_to do |format|
      format.html 
      format.js   { :nothing => true }
    end
    

    The thing it, you should probably return something. Even if it is an AJAX call, you should send something back to let the caller know that the creation was a success.

    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.

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

Sidebar

Related Questions

I have a class Communicator that works in a background thread receiving data on
I have a coming_soon_controller that displays a form for users to subscribe to an
I have a Java web application that uses CometD. The workflow is simple: I
I have a rabbitmq queue subscriber that spins up a new thread every time
I have event manager process that dispatches events to subscribers (e.g. http_session_created, http_sesssion_destroyed). If
Suppose I have a base class named Visitor, and it has 2 subclass Subscriber
I have a C# app that subscribes to a topic on our messaging system
I have form with one input for email and two submit buttons to subscribe
I have a system whereby a user can view categories that they've subscribed to
I have a Camera class that produces very large images at a high FPS

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.