ActiveAdmin:如何覆盖索引控制器操作:nil:NilClass的未定义方法“ base” [英] ActiveAdmin: How to override index controller action: undefined method `base' for nil:NilClass
问题描述
我正在尝试覆盖ActiveAdmin控制器的索引操作,以使其显示current_user的结果而不是所有结果。
I'm trying to override the index action of the ActiveAdmin controller for it to display results for the current_user instead of all results.
controller do
def index
@user_tasks = UserTask.where(:user_id => current_user.id).page(params[:page])
end
end
访问ActiveAdmin时,抛出异常:
When accessing ActiveAdmin, an exception in thrown:
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'
。
I'm using rails 3.1 and the latest ActiveAdmin version. 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
ActiveAdmin 0.4.4 now supports scoping queries without overriding this method. please see here: http://activeadmin.info/docs/2-resource-customization.html#scoping_the_queries
如果您的管理员具有不同的访问级别,则有时
可能需要范围他们可以访问的内容。假设您的用户模型具有
正确的has_many关系,则可以简单地对清单
和查找者进行范围划分:
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
这篇关于ActiveAdmin:如何覆盖索引控制器操作:nil:NilClass的未定义方法“ base”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!