Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show booleans in Active Admin as 'Yes' and 'No'

How can I make active admin to show "Yes" and "No" instead of "true" and "false".

I tried to change in english locale but that doesn't work. I'm thinking of monkeypatching boolean classes, but this seems quite ugly.

Is there anything else I can do?

like image 637
welldan97 Avatar asked Apr 26 '12 08:04

welldan97


4 Answers

You might like to do something like this:

index do
  id_column
  column(:published) do |story| 
    story.published? ? status_tag( "yes", :ok ) : status_tag( "no" )
  end
end

This will wrap the words "yes" and "no" in status tags which look rather good.

like image 162
superluminary Avatar answered Nov 05 '22 17:11

superluminary


Try to use condition directly in active admin as below

column :column_name do|object|
    object.column_name? ? 'Yes' : 'No'
end
like image 16
Krishna Srihari Avatar answered Nov 05 '22 16:11

Krishna Srihari


Here, this works, it gives you a tick and cross, but appears to be easy to modify.

https://gist.github.com/2574969

You'll need to restart your rails server for this to work, as it modifies the active_admin.rb initialiser.

Of course it creates a class, which is what you want to avoid, but in the absence of anything else, this does work.

like image 10
Ahmad Avatar answered Nov 05 '22 16:11

Ahmad


Its very simple,

Suppose your Boolean field name is active,

create a method named status like

def status
  self.active ? "Yes" : "No"
end

Use the status as a normal field in active admin show or index.

like image 3
Jyothu Avatar answered Nov 05 '22 16:11

Jyothu