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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:07:53+00:00 2026-06-13T14:07:53+00:00

I’m trying to get a nested form to submit via AJAX, but I can’t

  • 0

I’m trying to get a nested form to submit via AJAX, but I can’t seem to figure it out. I’ve searched far and wide for a solution, but all in vain. I’ve seen a few similar questions on here, but none with helpful answers. I have all the necessary inclusions in my application.html.erb layout, all the gems, etc. Using Rails 3.1.1 and Ruby 1.9.2p290.

Below are my models…

class Parent < ActiveRecord::Base
    has_many :children, :dependent => :destroy
    accepts_nested_attributes_for :children
end

class Child < ActiveRecord::Base
    belongs_to :parent
end

And here’s my form…

<%= form_for @parent.children.new, :remote => true do |t| %>

# form fields...

<%= t.submit 'Save', :class => 'button close_modal', :id => 'submit_button' %>

My children controller…

respond_to :html, :js, :json

def create
    @child = Parent.create(params[:child])
    respond_with(@child.parent)
end

And finally my create.js.erb file in the views/children folder (this is just to test)…

$("#notice").html('this works')

When all the above didn’t work, I tried adding this script to the form…

jQuery.ajaxSetup({ 
    'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});

$("#submit_button").submit(function(){
    $.post($(this).attr("action"), $(this).serialize(), null, "script");
    return false;
})

But still no luck. The code I’ve displayed here will submit the form via the children controller, then redirect me back to the parent/show view, which is where the child form is. But if I remove “responds_with(@child.parent)” from the children controller, I get the following error…

Template is missing

Missing template children/create, application/create with 
{:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. 
Searched in: * "C:/Users/Owner/My Documents/Aptana Studio 3 Workspace/my_app/app/views" 
* "c:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.5.2/app/views"

So in either case, I’m guessing that the form is not submitting via AJAX. And I have no idea why. I’m somewhat new to Rails, and to programming in general, so I don’t understand a whole lot about what’s going on behind the scenes with the Rails framework.

One other note that may or may not be relevant, I’ve noticed that some of my jQuery doesn’t work on elements in hidden divs when I show them. For example, this form I’m working on is rendered via jQuery by showing a hidden div, and it seems like I have to re-write some of the button scripts in the partial itself, because the script I’ve included in the application.js file doesn’t work on these buttons like it does on the rest.

However, I don’t think that’s the problem, because I put the form straight in the view (unhidden), but it still didn’t work.

EDIT

I’ve now noticed that the form is submitting via HTML, and not JS. So for some reason, the Rails jQuery is not binding to the form and overriding the default submit action. What might be causing that?

EDIT

After further research, I’m suspecting that the issue has something to do with the fact that I’m using a custom jQuery file from ThemeRoller. Is there something I’m supposed to do to make sure that my custom jQuery doesn’t interfere with the built in Rails jQuery?

Any thoughts??

  • 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-13T14:07:54+00:00Added an answer on June 13, 2026 at 2:07 pm

    Ah ha!!! So it turns out that I was including the jQuery libraries twice, and I’m assuming in the wrong order. I had downloaded a custom jQuery theme from ThemeRoller AND I had a link to the Google CDN in my application.html.erb file. So I deleted the reference to the Google CDN in my application header, then included some “//= require” lines in my application.js file to reference my custom jQuery files.

    //= require jquery-1.8.2
    //= require jquery-1.8.24.custom.js
    //= require jquery-ui
    //= require jquery_ujs
    //= require_tree .
    

    This seems to have resolved the conflict, and now my Rails AJAX calls are working just dandy!

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.