How to customize one column and display remaining in activeadmin
Solution 1
If you specify an index block, you need to put all the columns that you want to show, because you are replacing the "default" behaviour.
In your case, you need to add the other 19 columns with something like:
ActiveAdmin.register Book do
index do
column :one
column :two
column :three
column :name
column :title
column :pages
column :description do
raw "<a class='view_description button'>View Description</a>"
end
end
end
Solution 2
How about this?
ActiveAdmin.register Book do
index do
columns_to_exclude = ["name"]
(Book.column_names - columns_to_exclude).each do |c|
column c.to_sym
end
column :description do
raw "<a class='view_description button'>View Description</a>"
end
end
end
Solution 3
In my case, I want only rename the one column, I have done this way ->
index do
column :one
column :two
....
column "View Description", :description # This will change you column label **description** to **View Description**
end
Solution 4
I was curious about this question too. Here is what I found
index do
column :id
active_admin_config.resource_columns.each do |attribute|
column attribute
end
end
Solution 5
This also works when you want add or customize just a single column to the default list (based on an association which is for a belongs_to).
ActiveAdmin.register Book do
index do
column :publisher do |book|
book.publisher.name
end
Book.column_names.each do |c|
column c.to_sym
end
end
end
Related videos on Youtube
Senthil
Love building Web & mobile apps. Currently coding in Ruby on Rails, Django, Angular JS, React JS and more.
Updated on September 15, 2022Comments
-
Senthil over 1 year
I am using Active admin gem in my rails app. I added resources book which has 20 columns, now i need to customize only one column and print the remaining as it is. I tried below code
ActiveAdmin.register Book do index do column :description do raw "<a class='view_description button'>View Description</a>" end end end
but which hides all the columns and show only description. Any help will be useful.
-
phoet over 11 yearsyou need to list all the rows if you start with customizations like so github.com/phoet/on_ruby/blob/master/app/admin/users.rb#L19
-
Senthil over 11 yearsits hell for big table then , thanks for the link.
-
-
istrasci over 9 yearsWas searching the internet everywhere for this! Thank you!
-
spinlock about 9 yearsThis is the best answer in StackOverflow.
-
Mayuresh Srivastava over 5 yearsBut in this case link(i.e. href) which shows by default on some columns i.e. referenced columns is not preserving. How to get that as well, without adding individual columns with link_to method?
-
Mayuresh Srivastava over 5 yearsBut in this case link(i.e. href) which shows by default on some columns i.e. referenced columns is not preserving. How to get that as well, without adding individual columns with link_to method?
-
vinhboy about 3 yearsMVP answer right here... This also works in
show do
etc... This is a good way to retrieve all the columns using active_admin internals -
Alex91ckua over 2 yearsjust one tip, better to use
link_to 'View Description', root_path, class: 'view_description button'
rather raw link