Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize one column and display remaining in activeadmin

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.

like image 484
Senthil Avatar asked Jan 19 '13 12:01

Senthil


4 Answers

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
like image 153
krhorst Avatar answered Nov 06 '22 16:11

krhorst


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
like image 20
Raul Avatar answered Nov 06 '22 17:11

Raul


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
like image 9
Sanjay Choudhary Avatar answered Nov 06 '22 17:11

Sanjay Choudhary


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

https://github.com/activeadmin/activeadmin/blob/5dbf9b690302ecb4ba0c0ce59b2fb4735c88b35c/lib/active_admin/views/index_as_table.rb#L261

like image 4
woto Avatar answered Nov 06 '22 16:11

woto