这似乎应该相对简单,但我在寻找答案时遇到了一些麻烦:
如何在 ActiveAdmin 中设置页面标题?
合并答案并添加一点:
大部分内容都在wiki 的这个页面上(或者我很快就会放在那里)。
在为 activeadmin 注册您的模型的文件中(例如 app/admin/user.rb),您可以拥有
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
搜索后发现,
您可以将 :title 属性添加到活动管理员的块中。
例如
1) 为索引页设置标题,
index :title => 'Your_page_name' do
....
end
2)设置显示页面的标题,
show :title => 'Your_page_name' do
....
end
如果有人(像我一样)仍然在行动中挣扎new:
def new
  @page_title="My Custom Title"
  super
end
不要忘记添加super。然而,edit行动不需要那个。
根据这篇文章,您可以在选择的操作中使用如下行:
@page_title="My Custom Title"
例如,要在诸如“新”之类的预先存在的操作中实现这一点,您可以执行以下操作:
controller do
  def new do
    @page_title="My Custom Title"
    new! do |format|
       format.html{render "my_new"}
    end
  end
end
我的例子:
class Course < ApplicationRecord
    has_many :lessons, dependent: :destroy
end
class Lesson < ApplicationRecord
  belongs_to :course
end
我想在其课程索引页面中显示课程标题,我测试了两种方法来做到这一点。
ActiveAdmin.register Lesson do
  belongs_to :course, optional: true
  permit_params :title
  controller do
    def index
      @page_title = " #{Course.find(params[:course_id]).try(:title)}"
      super
    end
end
ActiveAdmin.register Lesson do
  belongs_to :course, optional: true
  permit_params :title
  controller do
    before_action {  
      @page_title = " #{Course.find(params[:course_id]).try(:title)}"
    }
  end
end
那么你可以使用@page_title
  index :title=> @page_title  do
    selectable_column
    id_column
    column :title
    actions
  end
如果我的问题是正确的,您想在 activeadmin 中重命名模型以在所有操作中以另一个名称出现,例如将“Post”模型重命名为在 ActiveAdmin 中显示“Article”,这样做只需转到 Admin 中的模型文件文件夹和第一行从
ActiveAdmin.register Post do
到
ActiveAdmin.register Post, as: "Article"
如果出现问题,请重新启动您的 Rails 服务器、docker 或其他任何东西
简单地做
index title: "Me new title"
如果您正在使用ActiveAdmin.register_page并想在顶部设置菜单名称和页面名称,请尝试以下操作:
ActiveAdmin.register_page "ReleaseNotes" do
  menu label: "Release Notes"
  
  content title: "Release Notes" do
    render partial: 'index'
  end
end