Allow for more customization of show action panels #1077

wants to merge 3 commits into


None yet

4 participants


Had a recent need to customize show action for AA resource. I like how there is active_admin_comments helper, which allows to display the admin comments panel. And then there is default_main_content, which displays both the resource properties AND the comment form.

But what if one wished to place a panel between the default panels? Well, I know you can use
attributes_table :attr_a, :attr_b, :etc
attributes_table *default_attribute_table_rows

But why dive into internals or repeat oneself if the default way to list the attributes is good enough? Right?

With these two commits, you can now render main show action panel separately.

show  do
  panel "X" do

You can still get the default way of doing things:

show do
  default_main_content_with_admin_comments  # too verbose?

Note on compatibility:
Unlike its sibling active_admin_comments, default_main_content method isn't publicly documented. This change would only affect those who made an effort to dig into AA internals. Any existing project explicitly calling default_main_content while customizing show action will lose the active_admin_comments panel (if it was enabled). But the same functionality can be restored by calling default_main_content_with_admin_comments now instead. Not a big deal really.

Swartz added some commits Feb 27, 2012
@Swartz Swartz Allow to display default_main_content for show action without includi…
…ng active_admin_comments by default.
@Swartz Swartz Let Show page work as before by including both default_main_content a…
…nd active_admin_comments panels to show action for AA resource.

Thanks for the pull request @Swartz.

Instead of changing the default_main_content method, maybe we could just extract to a method called #default_attributes_table? That way nothing changes and you now have access to the method you're looking for.

The idea behind default_main_content is that plugins can easily hook in here to add content to the default show screen (not publicly documented yet).

@gregbell gregbell was assigned Mar 8, 2012

Hi Greg,

Perhaps I'm not seeing the big picture here.
But default_main_content_with_admin_comments just piggiebacks on default_main_content.
Couldn't a plug-in use either as a hook ?

And FWIW, default_main_content sounds like it's meant for displaying the "main" content of the page (in this case details for a given record). Admin comments seem kind of secondary if enabled at all.

If you think extracting that chunk to just another method is a better design choice for the long run, I'm fine with that. Either way works for me.

@Swartz Swartz Quick fix for active_admin not honoring subURI when redirecting upon …
…successful logout from admin. Takes your to /admin instead of /some_subURI/admin.

I would love to see this incorporated one way or another as I ran into this today.

For now, I've done the following as a workaround:

show do
  attributes_table *default_attribute_table_rows
  panel "Extra Stuff" do
    # ...
Active Admin member

I'm thinking a better syntax than the one proposed here would be this

# Renders the default table
show do

# Renders the default table, except specific attributes
show do
  attributes_table except: [:foo, :bar]

@Daxter Agreed, that was what I expected, too. I think having attributes_table and active_admin_comments is a reasonable split since currently, attributes_table by itself creates a blank table, which I can't imagine anyone needing.

@seanlinsley seanlinsley was assigned Apr 17, 2013
Active Admin member

This is being replaced by #2138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment