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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:44:06+00:00 2026-06-17T22:44:06+00:00

Alright, I’m a JS / JQuery / Coffeescript noob. This is probably easy points

  • 0

Alright, I’m a JS / JQuery / Coffeescript noob. This is probably easy points for someone.

Having successfully implemented RBate’s Nested Form Model railscast, I am attempting to reproduce this in a simpler model: Chapters have many counties.

I have a chapters.js.coffee file with the following code:

jQuery ->
  $('form').on 'click', '.remove_fields', (event) ->
    $(this).prev('#destroy').val('1')
    $(this).closest('fieldset').hide()
    event.preventDefault()

This code works just fine in the other model. But not here.

_chapters_form.html.erb:

<div class="row span12">    
<%= form_for(@chapter) do |f| %>
    <%= render 'shared/error_messages', object: f.object %>
    <div class="span2"><strong>Chapter name:</strong></div>
    <div class="span6"><%= f.text_field :name %></div>
    <div class="span2"><strong>Chapter Number:</strong></div>
    <%= f.number_field :chapter_num, class: "span2" %>
</div>
<div class="row span12">
<div class="span12">
    <%= f.fields_for :counties do |builder| %>
        <%= render 'county_fields', f: builder %>
    <% end %>
</div>
    <% if f.object.new_record? then link = 'Add the Chapter' else link = 'Update Chapter' end %>
      <%= f.submit "#{link}", class: "btn btn-large btn-primary" %>
      <%= link_to "Cancel", chapters_path, class: "btn btn-large btn-primary" %>
    <% end %>
</div>

and:

_county_fields.html.erb:

<fieldset>
<div class="well span12">
    <div class="row span12">
        <div class="span3">County Number: <br /><i>(6-digit FIPS code)</i></div>
        <div class="span2"><%= f.number_field :county_num %></div>
        <div class="span2">County Name:</div>
        <div class="span5"><%= f.text_field :name %></div>
    </div>
    <div class="row span12"><hr></div>
    <div class="row span12">
        <div class="span6">Move to new Chapter:</div>
        <div class="span6"><%= select(:county, :chapter_id, Chapter.all.collect {|c| [c.name, c.id]}) %></div>
    </div>
    <div class="row span12">
        <div class="pull-right">
            <%= f.hidden_field :_destroy, id: "destroy" %>
            <%= link_to "remove county", "#", class: "remove_fields" %>
        </div>
    </div>
</div>
</fieldset>

There are no errors in the JS. Again, noob speaking, but it doesn’t seem that the JS is getting called. Clicking <%= link_to "remove county", "#", class: "remove_fields" %> just adds the # to the URI.

What am I doing wrong?

As requested, the HTML in a fiddle which doesn’t work either.

  • 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-17T22:44:07+00:00Added an answer on June 17, 2026 at 10:44 pm

    Your HTML is broken. You open a div before the form element, then close it before you close the form. If you move the form element up to just inside the container div, it works.

    <body>
      <div class="container-fluid">
        <form accept-charset="UTF-8" action="/chapters/7" class="edit_chapter" id="edit_chapter_7" method="post">
          <div class="row-fluid">
    ...
         </div>
        </form>
      </div>
    </body>
    

    You should take more care in the indenting of your HTML to help avoid this sort of simple mistake. Code format matters.

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

Sidebar

Related Questions

Alright I am having a world of difficulty tracking down this memory leak. When
Alright, I have this code: jquery //add watermark effect to the specified input box
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have no idea how to even begin doing this But basically
Alright I created some custom classes for my project sourced from this tutorial ,
Alright, so I got this code for gluLookAt: lookAt = new Vector3f(-player.pos.x, -player.pos.y, -player.pos.z);
Alright, I'll try and make this brief as possible. I wanted to a UIToolbar
Alright. I'm not sure how to explain this correctly, and the title of this
Alright I know my error and what it means. But, could someone show me

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.