40

我正在使用 Activeadmin 作为我正在开发的应用程序的管理界面(喜欢它),我很好奇是否有办法禁用资源显示页面右上角的“新资源”链接?

我正在使用的特定资源嵌套在另一个资源中,并且我有一个允许从该父资源的显示页面创建它的部分资源。

我已禁用菜单中的资源,但我宁愿将资源留在菜单中,这样我就可以查看/编辑/删除这些资源,而无需通过查看其父资源来找到它。

4

9 回答 9

70

以前的解决方案对我不起作用,所以这里是通用的解决方案,它总是有效的:

ActiveAdmin.register Book do
  actions :index

  #or like that
  #actions :all, :except => [:destroy]

  index do
    column :title
    column :author
  end  
end
于 2011-11-08T17:50:37.717 回答
34

尝试config.clear_action_items!删除New表格顶部的链接和其他链接

于 2011-10-20T11:45:51.763 回答
27

这从右上角删除了“新资源”按钮:

    config.clear_action_items!

这删除了“新资源”按钮以及“还没有资源 - 创建一个”框。

    actions :all, :except => [:new]

谢谢你,伊里奥

于 2013-05-29T07:52:19.513 回答
10
config.clear_action_items!

将删除所有操作。如果您只想删除新的操作链接,您还可以使用:

config.remove_action_item(:new)
于 2016-01-11T16:06:23.490 回答
8

我知道这是一个老问题,但我刚刚提出来(遇到同样的问题),并意识到这一点config.clear_action_items!并且actions :all, :except => [:new]根本不同。

config.clear_action_items!将从New索引页面中删除按钮,同时actions :all, :except => [:new]删除按钮和路线,这意味着您不能从另一个地方调用它(在我的情况下,这是需要的)。

于 2015-05-27T15:58:24.277 回答
6

我这样做了:

controller do
  def action_methods
    if some_condition
      super
    else
      super - ['new', 'create', 'destroy']
    end
  end
end

禁用一些可能的操作。action_methods返回包含 7 个标准 CRUD 操作的数组,因此您可以减去不需要的操作

于 2016-05-05T01:22:34.390 回答
4

甚至:

ActiveAdmin.register Purchase do
  config.clear_action_items!
  actions :index
end
于 2012-11-23T11:23:46.460 回答
0
Worked for me too ! :-) 

ActiveAdmin.register AssetSumView do
             menu :label => "Asset Summary View", :parent => "Things"
# no button for NEW (since this is a db view)
#---------------------------------------------------------------------------------------------
config.clear_action_items!

    enter code here

   action_item do
      link_to "Assets" , "/admin/assets" 
    end

   action_item do
      link_to "AssetCatgCodes", "/admin/asset_catg_codes"
    end

#---------------------------------------------------------------------------------------------
于 2012-07-15T16:34:07.780 回答
0

config.clear_action_items!只完成了一半的工作。不过有一个问题。

如果索引表为空,活动管理员会显示此消息

还没有[资源]。创建一个

上面的命令不会隐藏它,我不想完全禁用该操作。因此,我保留了链接并编辑了新操作以通过消息重定向到父资源索引。

controller do
  def new
    if params[:parent_id].present?
      super
    else
      redirect_to parent_resources_path, notice: "Create Resource through ParentResource"
    end
  end
end
于 2021-08-04T14:17:50.320 回答