Rails 3 devise, current_user is not accessible in a Model ?

Viewed 43521

in my project.rb model, I'm trying to create a scope with a dynamic variable:

scope :instanceprojects, lambda { 
    where("projects.instance_id = ?", current_user.instance_id)
} 

I get the following error:

undefined local variable or method `current_user' for #<Class:0x102fe3af0>

Where in the controller I can access current_user.instance_id... Is there a reason the model can't access it and a way to get access? Also, is this the right place to create a scope like the above, or does that belong in the controller?

4 Answers
Related