I am just trying to have the current_user only view students from his or her site. I wrestled with this many times and others say this should work but it only returns an empty set:
StudentsController
def index_scoper if current_user.role_id == 8 if current_user.contact and current_user.contact.contactable students = current_user.contact.contactable.students else students = end else super.with_state.with_site end end
Students Model named_scope :contactable, lambda { |current_user|
case when current_user.contact.contactable_id = 1 && current_user.contact.contactable_type = 'site' then { :conditions => {:site_id => 1}} when current_user.contact.contactable_id = 2 && current_user.contact.contactable_type = 'site' then { :conditions => {:site_id => 2}} end
Model relationships: A contact has_one user. A contact belongs_to site via contactable_id and contactable_type (polymorphic relationship). A site has_many students.
Any suggestion or clue as to why the named_scope doesn't show students with site_id same as the current_user?