Genuity Tech Blog

Tidbits of Ruby, Rails, and all things related

Page title for custom ActiveAdmin actions

I recently needed to customize the page title of a custom ActiveAdmin action. This is how I did it:

1
2
3
4
5
ActiveAdmin.register Customer do
  collection_action :import do
    @page_title = "Import Customers"
  end
end

I got the idea after seeing this in the active_admin source:

ActiveAdmin::Views::Pages::Base#set_page_title GitHub
1
2
3
4
# Set's the page title for the layout to render
def set_page_title
  set_ivar_on_view "@page_title", title
end

If there is a better way to do this, somone please leave a comment. I’ve also updated the ActiveAdmin wiki page related to this.

Update: 2012-04-12

I’ve recently submitted a pull request to active_admin that will let you set the page title declaratively, staying consistent to how this is done for the other standard actions:

1
2
3
4
5
ActiveAdmin.register Post do
  collection_action :comments, :title => "My Awesome Comments" do
    # do stuff
  end
end

If this PR is accepted, this will be a better solution, and I will update this post as well as the ActiveAdmin wiki.

Comments