Created
November 5, 2014 08:46
-
-
Save adomas-s/802ea7cbeaad168c70be 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
class Filter < ActiveRecord::Base | |
belongs_to :context, polymorphic: true | |
belongs_to :filter, polymorphic: true | |
end | |
class Foo < ActiveRecord::Base | |
has_many :filters, as: :context | |
def role_filters | |
self.filters.where(filter_type: 'Role') | |
end | |
def shop_filters | |
self.filters.where(filter_type: 'Shop') | |
end | |
def role_filter_ids | |
role_filters.map(&:filter_id) | |
end | |
def shop_filter_ids | |
shop_filters.map(&:filter_id) | |
end | |
def role_filters= | |
// complicated stuff goes here, instead of controller! | |
end | |
def shop_filters= | |
// complicated stuff goes here, instead of controller! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment