Activeadmin 禁用“新资源”方法

发布于 2024-12-10 22:58:26 字数 200 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

千柳 2024-12-17 22:58:26

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

ActiveAdmin.register Book do
  actions :index

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

  index do
    column :title
    column :author
  end  
end

Previous solution didn`t work for me, so here is general solutions, that works always:

ActiveAdmin.register Book do
  actions :index

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

  index do
    column :title
    column :author
  end  
end
淡紫姑娘! 2024-12-17 22:58:26

尝试 config.clear_action_items! 删除指向 New 的链接以及表格顶部的其他链接

Try config.clear_action_items! to remove the link to New and other links on top of the table

许你一世情深 2024-12-17 22:58:26

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

    config.clear_action_items!

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

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

谢谢你,伊里欧

This removed the "New Resource" button from the top-right:

    config.clear_action_items!

This removed both the "New Resource" button as well as the box "There are no resources yet - create one".

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

Thank you, Irio

中性美 2024-12-17 22:58:26
config.clear_action_items!

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

config.remove_action_item(:new)
config.clear_action_items!

Will remove all the actions.
If you only want to remove the new action link you can also use:

config.remove_action_item(:new)
那些过往 2024-12-17 22:58:26

我知道这是一个老问题,但我刚刚想到它(有同样的问题),并意识到 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! and actions :all, :except => [:new] are fundamentally different.

config.clear_action_items! will remove the New button from the index page, while actions :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).

維他命╮ 2024-12-17 22:58:26

我这样做了:

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

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

I did this:

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

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

超可爱的懒熊 2024-12-17 22:58:26

或者甚至:

ActiveAdmin.register Purchase do
  config.clear_action_items!
  actions :index
end

Or even:

ActiveAdmin.register Purchase do
  config.clear_action_items!
  actions :index
end
孤凫 2024-12-17 22:58:26

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

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

There are no [Resources] yet. Create one

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.

controller do
  def new
    if params[:parent_id].present?
      super
    else
      redirect_to parent_resources_path, notice: "Create Resource through ParentResource"
    end
  end
end
雅心素梦 2024-12-17 22:58:26
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

#---------------------------------------------------------------------------------------------
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

#---------------------------------------------------------------------------------------------
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文