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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:12:09+00:00 2026-06-01T07:12:09+00:00

I am creating a Rails 3 app that makes use of a nested form

  • 0

I am creating a Rails 3 app that makes use of a nested form with two levels of nested attributes, i.e.

<%= form_for @workareas do |f| %>
   <%= f.text_field :workarea_name %>
   <%= f.fields_for :projects  do |project| %>
      <%= f.text_field :project_name %>
      <%= f.fields_for :tasks  do |task| %>
         <%= f.text_field :task_name %>   
         <%= f.check_box :complete %>
         <%= f.check_box :urgent %>
         <%= f.check_box :today %>
      <% end %>
   <% end %>
<% end %>

(I realize this pseudocode is not 100% valid)

I’m using cocoon to handle nested forms. I was using Ryan’s nested_forms, but switched as Coccon seemed better able to deal with this issue.

I would like to display the tasks within a table, something like:

<table class="tasks">
  <tr>
    <th><%= f.label :task_name %></th>
    <th><%= f.label :complete %></th>
    <th><%= f.label :urgent %></th>
    <th><%= f.label :today %></th>
  </tr>
  <%= f.fields_for :tasks do |task| %>  
    <tr>
       <td><%= f.text_field :task_name %></td>
       <td><%= f.check_box :complete %></td>
       <td><%= f.check_box :urgent %></td>
       <td><%= f.check_box :today %></td>
    </tr>
  <% end %>
</table>
<%= link_to_add_association "New Task", f, :tasks %>

I’m running into problems inserting new tasks into the correct location in the layout. This is because there will be multiple task tables, one under each project on the view.

I realize I can use a script to specify the position where fields are added:

$(function() {
    $("a.add_fields.").
      data("association-insertion-position", 'after').
      data("association-insertion-node", '.tasks tr:last');
});

But can’t figure out how to pass in which project the tasks belong to. For example, if I have two projects, and try to add tasks to the 2nd project, the fields are currently being added to the 1st project. (They are correctly associated with project 2 on save however, this is purely a layout issue).

Has anyone run into this issue before? Is there a better selector to use for the “association-insertion-node”. I’d welcome any pointers or suggestions.

Thanks!!

UPDATE

I still haven’t managed to find a solution to this. Essentially what I want to do is add nested child elements, contained within a <tr> block, to a parent form. I have not been able to make this work the way I would like/ expect.

As an interim solution, I am now rendering the child elements within a <li> block. The <li> block contains a complete <table><tbody><tr> block for each child. This is less than ideal in terms of formatting, but the best I’be been able to come up with.

I’m going to leave this question open, for the time being at least, in the hopes that someone can provide a better solution.

Thanks to everyone that has replied so far.

  • 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-01T07:12:10+00:00Added an answer on June 1, 2026 at 7:12 am

    I didn’t find an easy way to solve this.

    In the end I had to over ride cocoon’s javascript with a custom function that essentially constructs a new association object name, and appends the new association object to the existing sequence.

    Not an easy solution. I will share it with Cocoon’s developer and maybe the gem can be updated to offer this functionality.

    Thanks for the suggestions.

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

Sidebar

Related Questions

I'm creating a form in a Rails 3 app that has a dropdown field.
I'm working on creating a Rails app that allows users to set availability Sunday
I'm creating an app that uses Rails to serve webpages and node.js/socket.io to facilitate
I have a controller in a Rails 3 app that, after creating a new
I'm creating a Ruby on Rails app that consists of stories. Each story has
I'm busy creating a very simplistic ruby on rails app that won't need a
I am creating a rails app and have used this code in one of
I'm creating a Rails app for students and high schools and I'm having some
I'm creating a Rails 3.1 app and I've the following big issue: I must
I'm creating an API for my Rails app, and I want to track how

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.