Hey all,
I keep getting the following error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.size

Based on the current user, when they navigate to a page, I want to limit
them to what they can see based on their site. Problem is there is no
association between site and user table directly. A contact has_one user
(user information is stored in current_user variable). A site has_many
contacts. And a site has_many students, where students table has a foreign
key of site_id. So there is a link between students and site, so when the
current user navigates to students page, they can only see students from
same site as them. I can do this by hard coding a number in a named_scope to
only display students for the site of the current_user. But different users
will belong to different sites so when logged in, the site their associated
with will change. That's the problem - to dynamically set that value in a
named_scope. This is what I have:

StudentsController

def index_scoper
  if current_user.role_id == 8
    super.site_staff_limit while current_user[:site_id] #The problem is the
user table has no site_id. There is no direct link between the users table
and sites table. However, there is a link between users and contacts and
then site and contacts and then site and students, where students table has
site_id.
  else
    super.with_state.with_site
  end
end

Student Model
    named_scope :site_staff_limit, lambda {|site_id| {:conditions =>
{:site_id => site_id}}}

Thanks for any suggestions.

-- 
View this message in context: 
http://old.nabble.com/dynamically-set-named_scope-based-on-current_user-tp27331346p27331346.html
Sent from the RubyOnRails Users mailing list archive at Nabble.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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to