Skip to content

Instantly share code, notes, and snippets.

@marcomd
Created February 10, 2012 11:27
Show Gist options
  • Save marcomd/1788853 to your computer and use it in GitHub Desktop.
Save marcomd/1788853 to your computer and use it in GitHub Desktop.
ActiveAdmin: Add attributes_table to generic resource
#Add this new method
#activeadmin-0.4.0\lib\active_admin\views\pages\show.rb
#after def attributes_table
def attributes_table_for_resource(specified_resource, *args, &block)
panel(I18n.t('active_admin.details', :model => "#{specified_resource.class.name} #{specified_resource.id}")) do
attributes_table_for specified_resource, *args, &block
end
end
#How to use it:
#app\admin\myresource.rb
ActiveAdmin.register MyResource do
show do |myresource|
attributes_table do
row :name
row :price do |myresource|
number_to_currency(myresource.price)
end
end
myresource.nested_resources.each do |nested|
attributes_table_for_resource(nested) do
row :description
row :created_at do |nested|
nested.created_at.strftime("%d/%m/%Y")
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment