活动管理员:如何设置页面标题?

这似乎应该相对简单,但我在跟踪答案时遇到了一些麻烦:

如何在ActiveAdmin中设置页面标题?

整合答案并添加一点:

大部分内容都在维基上的这个页面上 (或者我很快就会把它放在那里)。

在为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 

根据这篇文章 ,您可以在选择的操作中使用如下所示的行:

 @page_title="My Custom Title" 

例如,要在“new”之类的预先存在的操作中实现此function,您可以执行以下操作:

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

如果有人(像我一样)仍然在努力采取行动:

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

别忘了添加super 。 但是, edit操作不需要。

简单地做

 index title: "Me new title"