Skip to content

Instantly share code, notes, and snippets.

@panSarin
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save panSarin/071e137e45f370f65ae9 to your computer and use it in GitHub Desktop.

Select an option

Save panSarin/071e137e45f370f65ae9 to your computer and use it in GitHub Desktop.
company scope
class Client < ActiveRecord::Base
include CompanyScope
end
# and so on for each model
module CompanyScope
extend ActiveSupport::Concern
included do
scope :for_company, -> (user) {
where("#{self.table_name}.company_id = ?", user.company_id) unless user.is_superadmin?
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment