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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:46:16+00:00 2026-06-18T01:46:16+00:00

I am using deeply nested model in my project (using simple_form and cocoon). Everything

  • 0

I am using deeply nested model in my project (using simple_form and cocoon). Everything works fine as long as all nested objects are new.

My problem is, that I want to create a nested object from an existing (nested) object.

Here is my model

class Application < ActiveRecord::Base
    belongs_to :submitter
    has_one :composition

    accepts_nested_attributes_for :submitter, :composition
end

class Submitter < ActiveRecord::Base
    has_one :spouse
    has_many :children
    has_many :receipts
    has_many :applications

    accepts_nested_attributes_for :spouse, :children, :receipts, :applications
end

class Child < ActiveRecord::Base
    belongs_to :submitter
    has_many :receipts
end

The working process looks like this:

new Application –> new Submitter –> new Child

All can be created using one form.

Additionally, I also want to implement the following process:

new Application –> existing Submitter –> new Child

The existing object should be chosen by a dropdown list box.

Here is the (simplified, working) code of the view:

new.html.erb

<%= simple_form_for(@application)  do |f| %>
    <%= f.simple_fields_for :submitter do |submitter| %>  
        <%= render "submitter_fields", :f => submitter %>
    <% end %>
<% end %>

_submitter_fields.html.erb

<%= f.input :firstname %>
<%= f.input :lastname %>
<%= render "child", :f => f %>

_child.html.erb

<div id="childs">
    <%= f.simple_fields_for :children do |child| %>
      <%= render "child_fields", :f => child %>
    <% end %>
    <div class="links">
        <%= link_to_add_association 'Add child', f, :children %>
    </div>
</div>

_child_fields.html.erb

<div class="nested-fields">
    <%= f.input :firstname %>
    <%= f.input :lastname %>
    <%= link_to_remove_association "Remove child", f %>
</div>

Now I want to add a dropdown list which is populated with all existing Submitters. For example:

<%= f.assosciation :submitter %>

And here starts my problem: To build the form for adding a new child to the selected submitter, I need to assign this object to the form builder. I have no idea how to do this.

Can somebody give me a hint how to implement this? Or is this scenario simply not possible?

Thanks in advance!

Christian

  • 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-18T01:46:17+00:00Added an answer on June 18, 2026 at 1:46 am

    simple_fields_for takes a second argument the object: https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/action_view_extensions/form_helper.rb#L33 maybe if you pass your existing submitter it will work.

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

Sidebar

Related Questions

Possible Duplicate: Dependency Hell — how does one pass dependencies to deeply nested objects?
I'm using c++ and i'm in a really deeply nested set of functions and
I have created a symbolic link to a deeply nested directory. Using symbolic link
I am using Nokogiri. Suppose I have a deeply nested path: //h1/h2/h3/h4/h5 I think
I'm using Perl's XML::Simple to parse deeply nested XML and would like to extract
Using droppable to provide feedback is not a good option due to their deeply
Using the Redis info command, I am able to get all the stats of
Working with deeply nested python dicts, I would like to be able to assign
Suppose we have to use in some function deeply nested pointer very extensively: function
I'm having a difficult time to find an opening div in deeply nested HTML

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.