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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:56:14+00:00 2026-05-30T05:56:14+00:00

I have a nested form in a Rails 3.1 app, using Cocoon gem. In

  • 0

I have a nested form in a Rails 3.1 app, using Cocoon gem.

In the child form, I have a link that, when clicked, should return the id of the child and pass it to a javascript function.

<%= form_for @parent do |f| %>
    parent fields...
    <%= f.fields_for :child  do |child| %>
    <%= link "run function", 'string-to-pass' => "#{child.id}" %>   
    child fields...
    <% end %>
<% end %>

What is the correct syntax to return a column variable from a nested record?

child.id returns undefined local variable or method "child"

I could define an @child variable in the parent controller, but how do I point it towards the child ID, rather than the parent ID?

I’m sure I’m missing something simple here, but I can’t see how this fits together?

Grateful for any suggestions or pointers to relevant information.

Thanks!

  • 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-05-30T05:56:16+00:00Added an answer on May 30, 2026 at 5:56 am

    I would suggest doing something like: child.object.id

    I haven’t tested it so please let me know if it works.

    EDIT:
    I have code like this in my view:

    <%= f.fields_for :children do |child| %>
      <%= render "child_fields", :f => child %>
    <% end %>
    

    And then in _child_fields.html.erb:

    <%= f.object.some_attribute %>
     and other view stuff
    

    And this works.

    Can you try adapting your code to be similar. One thing I just realized, in your fields_for you need to say:

    <%= f.fields_for :children
    

    rather than:

    <%= f.fields_for :child
    

    Assuming, of course that you have a one-to-many relation going on here.

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

Sidebar

Related Questions

I have a nested form in a rails view that is called like this
I have a three-level multi-nested form in Rails. The setup is like this: Projects
In my Rails app I have a nested form_for in my show action. This
I am having some issues with nested models in a form, using Rails 3.1rc4.
I am trying to create form that contains another model in rails. I have
I have a rails 3 form with nested attributes. So, for example, the parent
I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I'm using the gem nested_form in a Rails 3.1 application. The problem is that
I have a nested model form that isn't functioning properly. The POST is to
I have a Rails form that is being used for creating and editing a

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.