title: ActiveRecord::Base.transaction with Rails .save
body: <p>It is my understanding that wrapping <code>.save!</code> in   <code>ActiveRecord::Base.transaction</code> will make sure all the models (User, Profile, and Setting) to save together or none at all.</p>
  
  <p>However, I was also told that including .save! with all the models.save! methods will also do that.  So essentially, both version 1 and 2 are the same.  I have a feeling I am wrong, so what is the difference?</p>
  
  <p>Thank you</p>
  
  <h3>Version 1</h3>
  
  <pre><code>def save
    if valid?
      ActiveRecord::Base.transaction do
        User.save!
        Profile.save!
        Setting.save!
      end
    else
      false
    end
  end
  </code></pre>
  
  <h3>Version 2</h3>
  
  <pre><code>def save
    if valid?
        User.save!
        Profile.save!
        Setting.save!      
    else
      false
    end
  end
  </code></pre>
  
  <p>Reference: <a href="https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html" rel="nofollow noreferrer">https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html</a></p>