ruby-on-rails – ActiveAdmin:如何覆盖索引控制器操作:nil的未定义方法`base’:NilClass

我正在尝试覆盖ActiveAdmin控制器的索引操作,以显示current_user的结果而不是所有结果.
controller do
  def index
    @user_tasks = UserTask.where(:user_id => current_user.id).page(params[:page])
  end
end

访问ActiveAdmin时,抛出异常:

ActionView::Template::Error (undefined method `base' for nil:NilClass):
    1: render renderer_for(:index)

我正在使用rails 3.1和最新的ActiveAdmin版本. gem“activeadmin”,:git => ‘https://github.com/gregbell/active_admin.git’.

解决方法

这不再是必需的.

ActiveAdmin 0.4.4现在支持范围查询而不覆盖此方法.
请看这里:http://activeadmin.info/docs/2-resource-customization.html#scoping_the_queries

If your administrators have different access levels,you may sometimes
want to scope what they have access to. Assuming your User model has
the proper has_many relationships,you can simply scope the listings
and finders like so:

ActiveAdmin.register Post do
     scope_to :current_user

     # or if the association doesn't have the default name.
     # scope_to :current_user,:association_method => :blog_posts
 end

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...