Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin display default view content

I am working with ActiveAdmin and need to make customizations to some views and have come across a couple of scenarios I feel I am doing wrong.

I am adding an additional table to a show view (comments on Posts). This requires me to rewrite the whole attributes table and then add my panel. Is there a way to customize views without losing the default content?

I would also like to add a table of associated items on the show view which doesn't need to be customized is there any way to include the default tale that would normally be on the index view with default actions and paging?

like image 616
Jason Yost Avatar asked Jul 22 '12 06:07

Jason Yost


3 Answers

After digging in the source code of Active Admin, I've found a way to patch this

  show do
    default_main_content
    panel "Your Added Stuff" do
      # Add stuff here
    end
  end

Of course this is undocumented and maybe considered a hack, but unless any other solution exists, it works.

Note: To do this in the form action (new and edit):

  form do |f|
    f.inputs
    # Other inputs here

    f.actions
  end
like image 156
Cristian Avatar answered Sep 27 '22 17:09

Cristian


Instead of using default_main_content, you could also just loop through the columns on the model like so:

ActiveAdmin.register Ad do
  show do
    attributes_table do
      default_attribute_table_rows.each do |field|
        row field
      end

      # Custom bits here

    end
  end
end
like image 36
MikeRogers0 Avatar answered Sep 27 '22 18:09

MikeRogers0


A couple areas of the documentation might help you:

  1. See Customize the Show Page, Customizing the Index Page, Customizing the Form, and Custom Pages. An example of customizing a show screen:

    ActiveAdmin.register Ad do
      show do |ad|
        default_main_content
        h3 ad.title
      end
    end
    
  2. See Custom Action Items in the Custom Controller Actions section of the documentation. An example:

    action_item :only => :show, :if => proc{ current_admin_user.super_admin? } do
         "Only display this to super admins on the show screen"
    end
    

NB default_main_content does not exist in the documentation anymore, yet it works fine.

like image 27
Michael Frederick Avatar answered Sep 27 '22 19:09

Michael Frederick