title: Rails update only empty fields
body: <p>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:</p>
  
  <p>How can I update only fields that are empty when using activeRecord? I have this code:</p>
  
  <pre><code>master_info.update_attributes( {:originalTitle =&gt; slave_info.originalTitle,                                                                         
  :starring =&gt; slave_info.starring,
  :theatrical =&gt; slave_info.theatrical }
  </code></pre>
  
  <p>And would like something like:</p>
  
  <pre><code>master_info.update_attributes( {:originalTitle =&gt; slave_info.originalTitle, if !master_info.originalTitle.present?                                                                        
  :starring =&gt; slave_info.starring, if !master_info.starring.present?
  :theatrical =&gt; slave_info.theatrical if !master_info.theatrical.present? }
  </code></pre>
  
  <p>I could do it one line at a time, but am trying to avoid that:</p>
  
  <pre><code>master_info.update_attributes(:originalTitle =&gt; slave_info.originalTitle) if !master_info.originalTitle.present?
  </code></pre>
  
  <p>I read something like:</p>
  
  <pre><code>master_info.update_attributes( {:originalTitle =&gt; slave_info.originalTitle,                                                                         
                            :starring =&gt; slave_info.starring,
                            :theatrical =&gt; slave_info.theatrical }.reject{ |key, value| value.present?} )
  </code></pre>
  
  <p>But this doesn't work, it doesn't update anything, not even empty fields. </p>
  
  <p>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. </p>
  
  <p>Here's hoping this one doesn't get a tumbleweed :)</p>