John Servinis
John Servinis

Reputation: 269

Rails ActiveAdmin max column length

In a Rails app using ActiveAdmin, one of my fields is printing an enormous length of text in a very narrow column and causing a single db row to take up an entire screen vertically. I only want ActiveAdmin to show the first ~50 chars with an ellipsis if it exceeds.

index do
  column :too_long
...

I am looking for something like this

index do
  column :too_long, :max => 50
...

Upvotes: 1

Views: 2627

Answers (3)

Dheeraj kumar
Dheeraj kumar

Reputation: 11

In Active admin to display a long text with a tooltip looks like below:

index do
    column "some_field" do |d|
        div(title: d.some_field) do
            truncate(d.some_field, length: 150)
        end
    end
end

Upvotes: 0

H6_
H6_

Reputation: 32808

You can also use the helper function truncate for this

index do
   id_column
   column :too_long do |my_resource|
      truncate(my_resource.too_long, length: 50)
   end
   actions
end

Upvotes: 4

Pritesh Jain
Pritesh Jain

Reputation: 9146

you can use something like

 index do
   column "TOO LONG" do |object|
      object.too_long.slice(0, 50)
   end
  #.....
 end

I have not tested this but something like this should work.

check more details in docs http://activeadmin.info/docs/3-index-pages/index-as-table.html

Upvotes: 3

Related Questions