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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:33:47+00:00 2026-05-14T00:33:47+00:00

I have started using jQuery and rails. I have made a simple form that

  • 0

I have started using jQuery and rails. I have made a simple form that submits to the database and updates the page without reloading with ajax.

In my jQuery functions I used $”#new_comment” for the id name (in my application.js and create.js.erb files) but on my places/show view file, I named the div “add_comment” and it works..

I renamed it new_comment and it breaks! Can someone explain it please? I get an error: “no action responded to 1”

My function in my controller is “create”.

#views/places/show.html.erb
<div id="new_comment" style="display:none">
 #form goes here
</div>

#application.js
jQuery.fn.submitWithAjax = function(){
    $("#new_comment").submit(function() {
    $.post($(this).attr("action"), $(this).serialize(), null, "script");
    return false;
    })
};


$(document).ready(function() {
    $("new_comment").submitWithAjax();
})

#create.js.erb
$("#new_comment").before('<div id="flash_notice"><%= escape_javascript(flash.delete(:notice)) %></div>');

$("#comments_count").html("<%= pluralize(@comment.place.comments.count, 'suggestion') %>");

$("#comments").append("<%= escape_javascript(render(:partial => @comment)) %>");

$("#new_comment")[0].reset();

#comments_controller.rb
    def create
      @place = Place.find(params[:place_id])
      @comment = @place.comments.create!(params[:comment])

    flash[:notice] = "Thanks for your suggestion. Remember to share with friends!"
    respond_to do |format|
      format.html {redirect_to place_comments_path(@place)}
      format.js
      end
end
  • 1 1 Answer
  • 1 View
  • 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-14T00:33:48+00:00Added an answer on May 14, 2026 at 12:33 am

    In addition to attaching the submit event to the wrong element, you are restricting your jquery plugin to just #new_comment. You should abstract it some and use the element that you’re passing in when you call submitWithAjax. You can add an id to the form or change the selector in your document.ready function to target the child form.

    #application.js
    jQuery.fn.submitWithAjax = function(myForm){
        $(myForm).submit(function() {
        $.post($(this).attr("action"), $(this).serialize(), null, "script");
        return false;
        })
    };
    
    
    $(document).ready(function() {
        $("#new_comment_form").submitWithAjax();
    })
    

    You’ll also need to correct the reset call in your create.js. The other javascript appears to do what you expect.

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

Sidebar

Related Questions

I have my application using jQuery heavily. The problem is that we started with
I have just started considering using the HTML 5 api for a Rails/JQuery project,
I have just started looking into jquerymobile, done simple samples using jquery.mobile-1.0a1 . I
I have made a simple accordion for my site using jQuery... It worked great,
I have started using ajax/jQuery in our websites / application. There are many plugins
I have just started using jQuery and although following code gets the job done,
Let me preface this question. I have just started using jquery, so please be
I have started using the DataTables plugin (v1.6.2) for jQuery (v1.4.2), and I would
I have started using leaflet as an open source map, http://leaflet.cloudmade.com/ The following jQuery
Guys i am very new to jQuery. I have started using the auto complete

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.