ActiveAdmin: how to override index controller action: undefined `base 'method for nil: NilClass

I am trying to override the action of the ActiveAdmin controller index so that it displays the results for current_user instead of all the results.

controller do def index @user_tasks = UserTask.where(:user_id => current_user.id).page(params[:page]) end end 

When accessing ActiveAdmin, the exception is:

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

I am using rails 3.1 and the latest version of ActiveAdmin. gem "activeadmin", :git => 'https://github.com/gregbell/active_admin.git' .

+6
source share
3 answers

This is no longer required.

ActiveAdmin 0.4.4 now supports select queries without overriding this method. see here: http://activeadmin.info/docs/2-resource-customization.html#scoping_the_queries

If your administrators have different levels of access, you may sometimes want to cover what they have access to. Assuming your user model has the correct has_many relationship, you can simply span lists and crawlers like this:

  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 
+4
source

I don't know why, but

 controller do def index index! do |format| @user_tasks = UserTask.where(:user_id => current_user.id).page(params[:page]) format.html end end end 

did the trick.

+8
source

Cancel the action as follows:

 controller do def scoped_collection # some stuffs super.where("type = ?", "good") end # other stuffs end 

That way, you can also run export functions (in xml, csv, ...) with the new collection that you redefined.

In my test, it only works where the condition and scope, and not the limitation.

Please note: https://github.com/activeadmin/activeadmin/issues/642

+2
source

Source: https://habr.com/ru/post/907125/


All Articles