Hey Glenn,

Can you paste your model/controller code into a gist or pastie?  Are you
using nested attributes with Rails 2.3 (
http://guides.rubyonrails.org/2_3_release_notes.html#nested-attributes) or
doing it manually?

James

On Mon, May 18, 2009 at 3:45 PM, Glenn Little <[email protected]> wrote:

>
> (Okay, yeah, that subject line is bad taken out of context!)
>
> I'm in a form-handler action where I have a parent record and a list of
> associated child records via a has_many association.
>
> I first walk through form params and look for matching child records
> in the database (via a hidden child_id form param) and if the record
> exists, I update the data, otherwise I create a new one via parent.build()
> and fill it in.  So now parent.children may have a mix of objects, some
> in the db and some not yet.
>
> Then I update various parent values from params.
>
> Then I walk through the parent.children records and do a child.save
> or child.destroy (depending on the new values and depending on various
> business
> rules).  Some of the destroy calls will be on child objects that have just
> been
> created and never put in the database (build() does not do an implicit
> save).  Some
> will be called on records that were in fact in the database.
>
> All good so far, but now I want to wave the updated parent record.
> The problem is that when I do the parent.save, I get a
> "can't modify frozen hash" error.
>
> I believe that's because the objects corresponding to any child records
> that were destroyed have been frozen.  But I'm not sure why the parent.save
> is trying to modify those objects?
>
> Given these issues, I'm starting to wonder if my whole paradigm is making
> my life more difficult than it needs to be.
>
> Any ideas on how to get around the frozen hash issue, or alternatively,
> the "right" way to do what I'm trying to do?
>
> Thanks much in advance...
>
>        -glenn
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to