Active Admin: How to set page title?

11,340

Solution 1

Consolidating answers and adding a little:

Most of this is on this page on the wiki (or I'll put it there soon).

Within the file that registers your model for activeadmin (e.g. app/admin/user.rb), you can have

ActiveAdmin.register User do
  # a simple string
  index :title => "Here's a list of users" do
    ...
  end

  # using a method called on the instance of the model
  show :title => :name do
    ...
  end

  # more flexibly using information from the model instance
  show :title => proc {|user| "Details for "+user.name } do
    ...
  end

  # for new, edit, and delete you have to do it differently
  controller do
    def edit
      # use resource.some_method to access information about what you're editing
      @page_title = "Hey, edit this user called "+resource.name
    end
  end
end

Solution 2

After searching got it,

You can add :title attribute to blocks of active admin.

e.g

1) To set title for index page,

index :title => 'Your_page_name' do
....
end

2) To set title for show page,

show :title => 'Your_page_name' do
....
end

Solution 3

In case someone (like me) still struggles with action new:

def new
  @page_title="My Custom Title"
  super
end

Dont forget to add super. However, edit action doesnt need that.

Solution 4

As per this post, you can use a line like the following in the action of choice:

@page_title="My Custom Title"

For example, to implement this in a pre-existing action like 'new', you would do something like this:

controller do
  def new do
    @page_title="My Custom Title"
    new! do |format|
       format.html{render "my_new"}
    end
  end
end

Solution 5

if I got your question right, you want to rename a model in activeadmin to appear with another name in all actions, for example renaming "Post" model to appear "Article" in ActiveAdmin, to do so just go to the model file inside Admin folder and the first line change from

ActiveAdmin.register Post do

to

ActiveAdmin.register Post, as: "Article"

and if something went wrong then restart your rails server, docker or whatever it is

Share:
11,340

Related videos on Youtube

user456584
Author by

user456584

Updated on June 12, 2022

Comments

  • user456584
    user456584 almost 2 years

    This seems like it should be relatively simple, but I've had some trouble tracking down the answer:

    How do you set the page title in ActiveAdmin?

  • bunty
    bunty almost 11 years
  • Nishutosh Sharma
    Nishutosh Sharma over 3 years
    Method definition with a block def new do Are you sure ?