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

  • Home
  • SEARCH
  • 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 8736099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:13:36+00:00 2026-06-13T10:13:36+00:00

I am working on a dynamically nested form using the cocoon gem. I have

  • 0

I am working on a dynamically nested form using the cocoon gem. I have two models

class CrossTable < ActiveRecord::Base
  attr_accessible :title, :table_name, :database, :folder_label_id, :foreign_fields_attributes

  belongs_to :folder_label
  has_many :foreign_fields

  accepts_nested_attributes_for :foreign_fields

  validates :title, :table_name, :database, :folder_label_id, presence: true

end


class ForeignField < ActiveRecord::Base
  attr_accessible :cross_table_id, :column_name, :description

  belongs_to :cross_table
  has_many :filter_sets


end

I have cocoon and jquery-rails in the gemfile
I added //=require cocoon to the application.js file

And here is my form partial

<%= simple_form_for @table do |f| %>
    <%= f.input :title %>

    <%= f.input :folder_label_id, :collection => @folders, :label_method => :title, :value_method => :id %>
    <br><br>
    <%= f.input :table_name %>
    <%= f.input :database %>

    <%= f.simple_fields_for :foreign_fields do |fields| %>
        <%= render 'foreign_field_fields', :f => fields %>
        <div id='links'>
            <%= link_to_add_association 'Add Field', f, :foreign_fields %>
        </div>
        <% end %>

    <%= f.button :submit %>

<% end %>

@table is an instance of the cross table model. Nothing in the foreign_field_fields partial shows up and link_to_add_association does nothing, and I get no errors. How can I start debugging this? Does anyone spot an error?

  • 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-13T10:13:37+00:00Added an answer on June 13, 2026 at 10:13 am

    You wrote the link_to_add_association inside the simple_fields_for, which will loop over all :foreign_fields and execute the given block. So if there are no foreign-fields yet, the link_to_add_association is never shown.

    You should write your view as follows (as documented):

    <%= simple_form_for @table do |f| %>
        <%= f.input :title %>
    
        <%= f.input :folder_label_id, :collection => @folders, :label_method => :title, :value_method => :id %>
        <br><br>
        <%= f.input :table_name %>
        <%= f.input :database %>
    
        <%= f.simple_fields_for :foreign_fields do |fields| %>
            <%= render 'foreign_field_fields', :f => fields %>
        <% end %>
        <div id='links'>
          <%= link_to_add_association 'Add Field', f, :foreign_fields %>
        </div>
    
        <%= f.button :submit %>
    
    <% end %>
    

    Hope this helps.

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

Sidebar

Related Questions

I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have been working on a project that dynamically creates a javascript file using
I'm working on a web page where I have a dynamically generated table where
I'm working on a project where the client wants to have existing pages dynamically
I have a UL and I'm working to dynamically add a new LI to
I have an iPad project I'm working on that dynamically creates a number of
I'm still trying to get my form working using Ryan Bates Nested_fom plugin. The
I'm working with iOS 5 and have dynamically generated cells in a table (2
I'm using formtastic & formtastic_cocoon to created a nested form. All seems to be
I have been working on a way to dynamically change the image src on

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.