Created
May 2, 2012 08:10
-
-
Save fred/2574969 to your computer and use it in GitHub Desktop.
extend active admin to prettier boolean values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It extends activeadmin to show pretty boolean values | |
# | |
# config/initializers/active_admin.rb | |
module ActiveAdmin | |
module Views | |
class TableFor | |
def bool_column(attribute) | |
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe } | |
end | |
end | |
class AttributesTable | |
def bool_row(attribute) | |
row(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe } | |
end | |
end | |
end | |
end | |
# example | |
# app/admin/user.rb | |
ActiveAdmin.register User do | |
index do | |
column :name | |
column :email | |
bool_column :admin | |
end | |
show do | |
attributes_table do | |
row :name | |
row :email | |
bool_row :admin | |
end | |
end | |
end |
its really helpful....i am looking for it from last two days
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And use this code if you just want to show the booleans with
status_tag
in AttributesTable view (no need of changingcolumn
methods tobool_column
: