Note that there are some explanatory texts on larger screens.

plurals
  1. POAccepts Nested Attributes For - edit form displays incorrect number of items ( + !map:ActiveSupport::OrderedHash {} )
    text
    copied!<p>I have a teacher profile model which has many subjects (separate model). I want to add subjects to the profile on the same form for creating/editing a profile. I'm using accepts_nested_attributes for and this works fine for creation. However on the edit page I am getting a very strange error - instead of seeing 3 subjects (I added three at create and a look into the console confirms this), I see 12 subjects(!). </p> <pre><code>#Profile model class Profile &lt; ActiveRecord::Base has_many :subjects accepts_nested_attributes_for :subjects end #Subject Model class Subject &lt; ActiveRecord::Base belongs_to :profile end #Profile Controller (only showing deviations from normal RESTFUL setup) def new @profile = Profile.new 3.times do @profile.subjects.build end end #Here's 1 of three parts of the subject output of = debug @profile errors: !ruby/object:ActiveRecord::Errors base: *id004 errors: !map:ActiveSupport::OrderedHash {} subjects: - &amp;id001 !ruby/object:Subject attributes: exam: Either name: "7" created_at: 2010-04-15 10:38:13 updated_at: 2010-04-15 10:38:13 level: Either id: "31" profile_id: "3" attributes_cache: {} # Note that 3 of these attributes are displayed despite me seeing 12 subjects on screen </code></pre> <p> </p> <p>Other info in case it's relevant.</p> <p>Rails: 2.3.5, Ruby 1.8.7 p149, HAML, inherited_resources</p> <p>I've never had so much difficulty with a bug before - I've already lost about 8 hours to it. Would really appreciate any help!</p> <p>Thanks to any courageous takers</p> <p>Jack</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload