
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.56 KB | hits: 14 | expires: Never
has_and_belongs_to_many_relationship but only for non-admin users
class Company
def self.for_user
if User.current.is_admin?
Company.all
else
User.companies
end
end
end
class User < ActiveRecord::Base
has_and_belongs_to_many :companies
end
class Admin < User
def companies
Companies.all
end
end
class User
has_and_belongs_to_many :companies do
def visible
if proxy_owner.can? "company:view_all"
Company.scoped
else
self
end
end
end
end
User.find(x).companies.visible