Skip to content

Instantly share code, notes, and snippets.

@adomas-s
Created November 5, 2014 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adomas-s/802ea7cbeaad168c70be to your computer and use it in GitHub Desktop.
Save adomas-s/802ea7cbeaad168c70be to your computer and use it in GitHub Desktop.
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