本文介绍了如何获得Active Admin的嵌套和非嵌套资源视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户有多次交易。我目前已将活动管理员设置为使用admin / transactions.rb中的belongs_to:user在基本CRUD的用户下嵌套事务。但是,我还需要事务的顶层视图,以显示跨用户的事务记录的子集。我该如何完成第二部分?

A user has_many transactions. I have active admin currently set to nest the transactions under user for basic CRUD using belongs_to :user in admin/transactions.rb. I also, however, need a top level view for transactions that shows a subset of transaction records that span across users. How can I accomplish this second part?

推荐答案

我认为现在最好的方法是传递可选选项: / p>

I think the best way now is to pass in the "optional" option:

ActiveAdmin.register Transactions do
  belongs_to :user, :optional => true
  ...
end

这样,您将从主导航菜单以及特定用户下的嵌套视图访问所有事务。

This way, you'll get to access all Transactions from the main navigation menu as well as the nested view under a particular User.

如果要查找更多内容,可以参考以下源代码:

If you want to find more, you can refer to the source code under:

131行

def include_in_menu?
  super && !(belongs_to? && !belongs_to_config.optional?)
end

这篇关于如何获得Active Admin的嵌套和非嵌套资源视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:51