Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin: Modifying Index Table Based on Active Scope

Suppose I have an ActiveAdmin model with two scopes like so:

ActiveAdmin.register Book do

  scope :all, default: true
  scope :smith #all books by author 'smith'

  index do
    column :title
    column :published_year
    column :author
  end
end

I don't want/need the 'author' column when the user has selected the 'smith' scope.

So is there a way to get access to the current scope and only show the author column in one of the scopes? I suppose for this example I could use a custom view and check the actual content of the data but I am hoping there is an easier and better way.

like image 256
Mark Fraser Avatar asked Dec 12 '12 07:12

Mark Fraser


2 Answers

you can try something like that

index do
    column :title
    column :published_year
    column :author unless params['scope'] == 'smith'
  end
like image 184
Fivell Avatar answered Oct 22 '22 18:10

Fivell


You also have access to the @current_scope object, and you can do @current_scope.scope_method to get the underlying scope method

like image 32
Sam Stickland Avatar answered Oct 22 '22 18:10

Sam Stickland