-
Notifications
You must be signed in to change notification settings - Fork 2
Concerns
cavalle edited this page Dec 23, 2012
·
13 revisions
http://weblog.jamisbuck.org/2007/1/17/concerns-in-activerecord
module Folder
def self.included(base)
base.has_many :files, :as => :owner, :dependent => :destroy
end
# This returns the path where files are to be uploaded
# for this specific "folder".
def attachment_path
"/path/to/files/for/#{id}"
end
endclass Message < ActiveRecord::Base
include Folder
#...
end
class Comment < ActiveRecord::Base
include Folder
#...
end- https://speakerdeck.com/seenmyfate/4-steps-to-faster-rails-tests
- http://confreaks.com/videos/641-gogaruco2011-fast-rails-tests
module DiscountCalculator
def total_discount
basket_items.collect(&:discount).inject(:+)
end
endclass Basket < ActiveRecord::Base
has_many :basket_items
include DiscountCalculator
end