Activeadmin 禁用“新资源”方法
我正在使用 Activeadmin 作为我正在开发的应用程序的管理界面(喜欢它),我很好奇是否有办法禁用资源显示页面右上角的“新资源”链接?
我正在使用的特定资源嵌套在另一个资源中,并且我有一个部分允许从该父资源上的显示页面创建它。
我已禁用菜单中的资源,但我宁愿将资源保留在菜单中,这样我就可以查看/编辑/删除这些资源,而不必通过查看其父资源来找到它。
I'm using Activeadmin for the admin interface on an app I'm working on (loving it) and I am curious if there is a way to disable the "New Resource" link in the upper-right corner of the resource show page?
The particular resource I'm using is nested inside another resource and I have a partial that allows it to be created from the show page on that parent resource.
I have disabled the resource in the menu, but I'd rather leave the resource in the menu so I can see/edit/delete those resources without having to find it by looking through its parent resource.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
以前的解决方案对我不起作用,所以这里是通用解决方案,始终有效:
Previous solution didn`t work for me, so here is general solutions, that works always:
尝试
config.clear_action_items!
删除指向New
的链接以及表格顶部的其他链接Try
config.clear_action_items!
to remove the link toNew
and other links on top of the table这删除了右上角的“新资源”按钮:
这删除了“新资源”按钮以及“尚无资源 - 创建一个”框。
谢谢你,伊里欧
This removed the "New Resource" button from the top-right:
This removed both the "New Resource" button as well as the box "There are no resources yet - create one".
Thank you, Irio
将删除所有操作。
如果您只想删除新操作链接,您也可以使用:
Will remove all the actions.
If you only want to remove the new action link you can also use:
我知道这是一个老问题,但我刚刚想到它(有同样的问题),并意识到 config.clear_action_items! 和 actions :all, : except => [:new] 本质上是不同的。
config.clear_action_items!
将从索引页中删除New
按钮,而actions :all, : except => [:new]
将删除按钮和路线,这意味着您无法从其他地方调用它(在我的情况下,这是需要的)。I know this is an old question, but I just came up to it (had the same problem), and realized that
config.clear_action_items!
andactions :all, :except => [:new]
are fundamentally different.config.clear_action_items!
will remove theNew
button from the index page, whileactions :all, :except => [:new]
will remove both the button, AND the route, meaning you can't call it from another place (which, in my case, is needed).我这样做了:
禁用一些可能的操作。 action_methods 返回 7 个标准 CRUD 操作的数组,因此您可以减去不需要的操作
I did this:
To disable some of the possible actions. action_methods returns an array of the 7 standard CRUD actions, so you can subtract those you don’t want
或者甚至:
Or even:
config.clear_action_items!
只完成了一半的工作。但有一个问题。如果索引表为空,活动管理员会显示此消息
不会被上述命令隐藏的命令,并且我不想完全禁用该操作。因此,我保留了链接并编辑了新操作,以通过消息重定向到父资源索引。
config.clear_action_items!
does only half of the job. There is one issue though.In case of empty index table, active admin show this message
which doesn't get hidden by the above command and I don't want to entirely disable the action. So, I kept the link and edited the new action to redirect to the parent resource index with a message.