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