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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 27, 10:31 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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}} > endThis looks odd - you''ve got single equals when you probable wanted to compare and not assign Fred> > 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? > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.