This has me pulling out my hair, despite being what’s going to turn out
to be a trivial problem.
For the sake of argument, let’s say I have two database tables, updates
and poems. The Update model includes has_one :poem, and Poem has
belongs_to :update. poems the table has update_id as well, just to be
clear about how it’s laid out. Also, for the sake of argument I’ll
mention that poems has a field called title, though there are others.
When I build an update I don’t automatically insert a poem, because
there isn’t necessarily going to be one per, but there’s an action to
create a poem later on. This action succeeds, inserting a new row into
poems with a unique id and linking to the correct update. If, at this
point, I set the title, it will save to the database as well. However,
once that object is attached to update, no amount of editing and saving
@update.poem.save will ever do anything to the database. Editing the
database directly will cause the page to return the correct values, so
it is clearly looking in the right place, but save just won’t work.
To make matters worse, or at least more maddening for me, throwing the
save statement into an if statement will always return true, despite not
actually saving anything. I’m sure I’m overlooking something stupid.
Any help would be greatly appreciated.