在我的项目中.rb模型,我试图用一个动态变量创建一个范围:
scope :instanceprojects, lambda {
where("projects.instance_id = ?", current_user.instance_id)
}
我得到以下错误:
undefined local variable or method `current_user' for #<Class:0x102fe3af0>
在控制器中我可以访问current_user.instance_id
...是否有模型无法访问它的原因,以及获得访问权限的方法?另外,这是创建上述范围的正确位置,还是属于控制器?