在我project.rb模型,我试图创建一个动态变量的作用域:Rails 3设计,current_user不能在模型中访问?
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
......模型无法访问它并有获取访问权限的方法吗?此外,这是创建上述范围还是属于控制器的合适位置?
太棒了。现在试试 – AnApprentice 2010-09-18 18:48:30
工作很好。谢谢! – AnApprentice 2010-09-18 19:34:10
我称范围'',所以它会很好地阅读。 'Project.of current_user' – romeroabelleira 2012-04-28 12:58:28