Saturday, June 7, 2008

before_save catch 22

I was attempting to update an attribute in my model using a value from a foreign key. I was not updating to what I was telling it to update to. So, I dove into the console to see what was happening. It turns out I was setting the code BACK to its original value in the before_save method. Not the behaviour I expected, because I didn't read the docs:

"Is called BEFORE Base.save"

# this hoses up the build_promotion process in the preferences screen, # but it is needed for adding and updating kids... catch 22 person.promotion_sequence = person.room.promotion_sequence

So, my value was getting overwritten by the old value. So, I commented out that line of code.

# person.promotion_sequence = person.room.promotion_sequence

Now, I hit my next problem. I went to update my record using an existing form via the update_attributes method. This did not work because the attribute that needed to be updated was NOT in the params. So, here is how I fixed it :

No comments:

Blog Archive

About Me

We are a family of 6...soon to be 7. We have 4 great kids, Simeon 9, Liesel 7, Jude 6, Hope almost 3. And Alina, soon to be Ava is 3. We are hoping to adopt her from Eastern Europe. We are excited as a family to help her accomplish her milestones, love her, and in turn know we will be blessed to have her in our lives.