简体   繁体   English

在 Rails / Active Admin 中,如何在索引标题中获取嵌套资源?

[英]In Rails / Active Admin, how do I get the nested resource in the index title?

I'm using active admin and I'd like to get the nested resource in the index title for optional nested resource, for example for the route:我正在使用活动管理员,我想在索引标题中获取可选嵌套资源的嵌套资源,例如路由:

For example I will have two models set up like this:例如,我将像这样设置两个模型:

ActiveAdmin.register Document do
end

ActiveAdmin.register Comment do
    belongs_to :doucment, optional: true

    index title: 'GET DOCUMENT HERE IF ON NESTED ROUTE' do
    end
end

How on earth do I access the parent doucment in the index title?我到底如何访问索引标题中的父文档? I've tried every possible thing I can think of going over the objects available there and can't find how to do this in the docs as well.我已经尝试了我能想到的所有可能的事情来检查那里可用的对象,并且在文档中也找不到如何做到这一点。 I've even tried to get the curren url to see if it has docuemnts in it, however routing is not available as well here.我什至尝试获取当前 url 以查看它是否有文档,但是这里也没有路由。

Thanks very much for your help.非常感谢您的帮助。

You can set the title with a proc like this:您可以使用这样的proc设置标题:

index(
  title: proc { 
    if params[:document_id].present? 
      "#{Document.find(params[:document_id])}"
    else
      "It was optional all along"
    end
  } 
) do
  # ...
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM