not having a lot of luck lately with answers in Stackoverflow (I think I'm the king of the tumbleweed award) but here goes anyway:
How can I update only fields that are empty when using activeRecord? I have this code:
master_info.update_attributes( {:originalTitle => slave_info.originalTitle,
:starring => slave_info.starring,
:theatrical => slave_info.theatrical }
And would like something like:
master_info.update_attributes( {:originalTitle => slave_info.originalTitle, if !master_info.originalTitle.present?
:starring => slave_info.starring, if !master_info.starring.present?
:theatrical => slave_info.theatrical if !master_info.theatrical.present? }
I could do it one line at a time, but am trying to avoid that:
master_info.update_attributes(:originalTitle => slave_info.originalTitle) if !master_info.originalTitle.present?
I read something like:
master_info.update_attributes( {:originalTitle => slave_info.originalTitle,
:starring => slave_info.starring,
:theatrical => slave_info.theatrical }.reject{ |key, value| value.present?} )
But this doesn't work, it doesn't update anything, not even empty fields.
In fact, what would be ideal is to not have to repeat the field names since they are all named the same in both master and slave, but I can't do a .each on an activeRecord. But that's a secondary problem, the primary one is updating the empty fields.
Here's hoping this one doesn't get a tumbleweed :)