活动管理员:如何设置页面标题? [英] Active Admin: How to set page title?

查看:76
本文介绍了活动管理员:如何设置页面标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

How do you set the page title in ActiveAdmin?

推荐答案

合并答案并添加一些内容:

Consolidating answers and adding a little:

大多数是在 Wiki上的此页面上(或者我会尽快放在那里)。

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

在为activeadmin注册模型的文件中(例如app / admin / user.rb),您可以拥有

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

这篇关于活动管理员:如何设置页面标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆