Created
May 29, 2014 20:18
-
-
Save mettledrum/db2faa1a94ff4302f54e to your computer and use it in GitHub Desktop.
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
# mixes in logic to make a model understand how to fetch its relationships | |
# based on the item_id/item_item_type field combination | |
module VariadicItem | |
extend ActiveSupport::Concern | |
included do | |
belongs_to :item_type | |
end | |
# get the item associated with the current polymorphic record into which this module has been mixed | |
def item | |
item_type.name.classify.constantize.find(item_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment