在 activeadmin 中隐藏一行

hide a row in activeadmin

我将 activeadmin 与 Ruby 2.2.1 和 Rails 4.2.0 一起用于故障单系统。我需要 hide/archive 已关闭的工单,但我不知道如何...

index do
 selectable_column
 column :ticket
 column :in_carico
 column :inoltrato
 column :categoria
 column :oggetto do |n|
   truncate(n.oggetto, omision: "...", length: 50)
 end
 column :note do |n|
   truncate(n.note, omision: "...", length: 30)
 end
 column :created_at
 column :stato
 actions defaults: true do |a|
   link_to 'Infoweb', "http://XXX/main/ticket_dettagli.asp?TT="+a.ticket , :target => "_blank"
end

结束

在 :stato 中我可以选择 3 种声音:working,suspended 和 closed。

示例使用 Post 模型。

您可以在 AA 中注册模型以存档 posts (/admin/archived_posts.rb):

ActiveAdmin.register Post, as: "Archived Posts" do
end

然后在Post模型中定义一个范围,只返回post,其中,例如status属性是archived:

scope :archived, -> { where(status: 'archived') }

然后在 AA 中已经注册的模型中,您在 scoped_collection 方法中使用此范围:

  ActiveAdmin.register Post, as: "Archived Posts" do
    # ...
    controller do
      def scoped_collection
        Post.archived
      end
    end
    # ...
  end

就是这样,您在 AA 的这个新标签中拥有所有存档的 post。

当然,现在没有 posts,其中 status 在 AA (/admin/posts.rb) 的常规 Post 选项卡中是 archived,将新范围添加到 Post 模型 (/models/post.rb):

scope :not_archived, -> { where.not(status: 'archived') } # or something like this

并在/admin/posts.rb

中的scoped_collection方法中使用它