Created
February 9, 2013 15:54
-
-
Save thegrubbsian/4745802 to your computer and use it in GitHub Desktop.
Code for the "Rails No Nos" blog post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
has_many :line_items | |
before_save :update_total | |
def update_total | |
self.total = line_items.pluck(:price).inject(:+) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment