Allow for more customization of show action panels #1077

Closed
wants to merge 3 commits into
from

Projects

None yet

4 participants

@Swartz

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
OR
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
  default_main_content
  panel "X" do
    ...
  end
  active_admin_comments
end

You can still get the default way of doing things:

show do
  default_main_content_with_admin_comments  # too verbose?
end

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.
975471f
@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.
244c4ce
@gregbell

Thanks for the pull request @Swartz.

Instead of changing the default_main_content method, maybe we could just extract https://github.com/gregbell/active_admin/blob/master/lib/active_admin/views/pages/show.rb#L44 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
@Swartz

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.
e460be6
@schmich

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
    # ...
  end
  active_admin_comments
end
@seanlinsley
Active Admin member

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

# Renders the default table
show do
  attributes_table
end

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

@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
@seanlinsley
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