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

use*_*584 18 ruby-on-rails ruby-on-rails-3 activeadmin

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

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

ces*_*oid 18

整合答案并添加一点:

大部分内容都在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
Run Code Online (Sandbox Code Playgroud)


bun*_*nty 8

搜索完之后,

您可以将:title属性添加到活动管理员的块中.

例如

1)设置索引页面的标题,

index :title => 'Your_page_name' do
....
end
Run Code Online (Sandbox Code Playgroud)

2)为节目页面设置标题,

show :title => 'Your_page_name' do
....
end
Run Code Online (Sandbox Code Playgroud)

  • 更多详情请查看:https://github.com/gregbell/active_admin/wiki/Set-page-title (2认同)

use*_*584 5

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

@page_title="My Custom Title"
Run Code Online (Sandbox Code Playgroud)

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

controller do
  def new do
    @page_title="My Custom Title"
    new! do |format|
       format.html{render "my_new"}
    end
  end
end
Run Code Online (Sandbox Code Playgroud)