可以将操作按钮添加到 activeadmin 上的仪表板 table 吗?

Can action buttons be added to dashboard table on activeadmin?

我有这段代码可以在 activeadmin 仪表板上创建 table:

columns do 
  column do
    panel "New Mentor's requests" do
      table_for User.where(mentor_request: true) do |t|
        t.column("Id") { |user| user.id }
        t.column("Name") { |user| user.account.full_name }
        t.column("Email") { |user| user.account.email }
        t.column("Organization") { |user| user.organization.name }

      end

    end
  end
end

有没有办法像其他资源一样添加 "actions"?我的意思是像 "new, edit, delete",但是是自定义的。

我尝试放置 "actions" 标签,但我得到了一个未定义的方法。

table_for 用于呈现不一定是 ActiveRecord 对象的对象集合,因此操作方法不像在 index 操作中那样可用。但是,您应该能够使用如下内容呈现您自己的操作:

column("View User") { |user| link_to "View", user_path(user) }

编辑 对于多个链接,您可以使用 Arbre 的 span 标签包装 link_tos:

column("View User") do |user|
  span link_to "View", "/mypath"
  span link_to "Edit", "/mypath"
  span link_to "Delete", "/mypath"
end

我正在使用带有 arbre 1.0.2 的 ActiveAdmin 1.0.0.pre2,我还没有在早期版本上尝试过。

你也可以试试这个:

ActiveAdmin.register Foo do
  actions :all
  index do
    column :name
    actions defaults: true do |foo|
      link_to "Custom ACTION", custom_action_path(foo.id)
    end
  end
end

比已定义的选项更多选项对我有用:查看编辑, 删除

来源:https://github.com/activeadmin/activeadmin/issues/53