Module: ActiveAdmin::ActsAsList::IndexMethods

Defined in:
lib/active_admin/acts_as_list/index_methods.rb

Instance Method Summary collapse

Instance Method Details

#sortable_columnsObject

Call this inside your index do…end bock to make your resource sortable.

Example:

#app/admin/players.rb

ActiveAdmin.register Player do
  index do
    # This adds columns for moving up, down, top and bottom.
    sortable_columns    
    #...
    column :firstname
    column :lastname
    default_actions
  end
end


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_admin/acts_as_list/index_methods.rb', line 21

def sortable_columns
  column "Placement" do |resource|
    
    actions = ActiveSupport::SafeBuffer.new
    
    unless resource.first?
      
      # Move to top
      actions << link_to([:move_to_top, active_admin_namespace.name, resource], class: :acts_as_list_arrow, title: I18n.t('acts_as_list.hovers.move_to_top')) do
        image_tag("acts_as_list/move_to_top.png")
      end
      
      actions << link_to([:move_up, active_admin_namespace.name, resource], class: :acts_as_list_arrow, title: I18n.t('acts_as_list.hovers.move_up')) do
        image_tag("acts_as_list/move_up.png")
      end
      
    end
    
    unless resource.last?
      
      # Move to bottom
      actions << link_to([:move_to_bottom, active_admin_namespace.name, resource], class: :acts_as_list_arrow, title: I18n.t('acts_as_list.hovers.move_to_bottom')) do
        image_tag("acts_as_list/move_to_bottom.png")
      end
      
      # Move down
      actions << link_to([:move_down, active_admin_namespace.name, resource], class: :acts_as_list_arrow, title: I18n.t('acts_as_list.hovers.move_down')) do
        image_tag("acts_as_list/move_down.png")
      end
    end
    
    actions

  end
end