[フレーム]
Last Updated: May 15, 2018
·
2.549K
· jgtr

Shortcut for customizing ActiveAdmin columns

I've been working with ActiveAdmin lately in Rails, and sometimes need to customize the index view of a model without rewriting all the attributes that I don't want to change.

I want to exclude a few columns simply without writing a bunch of ActiveAdmin dsl.

The code below does this simply and is easily embeddable into the ActiveAdmin dsl.

Colleague is my model name below. Replace it with yours.

The code below goes in the /app/admin/colleague.rb

ActiveAdmin.register Colleague do

 index do
 excluded = ["bio", "phone", "created_at"]
 (Colleague.column_names - excluded).each do |c|
 column c.to_sym
 end
 end

end

AltStyle によって変換されたページ (->オリジナル) /