Mirko Spezie
Mirko Spezie

Reputation: 43

hide a row in activeadmin

I'm using activeadmin with Ruby 2.2.1 and Rails 4.2.0 for a trouble ticketing system. I need to hide/archive the closed tickets, but I don't know how...

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

end

In :stato I can choose 3 voices: working, suspended and closed.

Upvotes: 1

Views: 899

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52357

Example using Post model.

You can register a model in AA for archived posts (/admin/archived_posts.rb):

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

Then in Post model define a scope, returning only post, where, for example, status attribute is archived:

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

Then in already registered model in AA you use this scope in scoped_collection method:

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

This is it, you have all the archived posts in this new tab of AA.

Of course, now, to not have posts, where status is archived in regular Post tab in AA (/admin/posts.rb), add new scope to Post model (/models/post.rb):

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

and use it in scoped_collection method in /admin/posts.rb

Upvotes: 1

Related Questions