Sha256: 0606412ba528af9777e13797539f81b324df16db24669563161ae14dea326240

Contents?: true

Size: 1020 Bytes

Versions: 5

Compression:

Stored size: 1020 Bytes

Contents

require 'activeadmin'

module ActiveAdmin
  # Include this module to registered page to enable
  # ActiveAdmin Sortable Table extension
  # @example
  #
  #  ActiveAdmin.register Category do
  #    include ActiveAdmin::SortableTable
  #    config.sort_order = 'position_asc'
  #    permit_params :position
  #
  #    index do
  #      handle_column
  #      id_column
  #    end
  # end
  #
  module SortableTable
    require 'active_admin/sortable_table/version'
    require 'active_admin/sortable_table/engine'
    require 'active_admin/sortable_table/handle_column'

    class << self
      # @param [ActiveAdmin::DSL] dsl
      # @return [void]
      #
      def included(dsl)
        dsl.instance_eval do
          member_action :sort, method: :post do
            resource.insert_at params[:position].to_i
            head 200
          end

          member_action :move_to_top, method: :post do
            resource.move_to_top
            redirect_to :back
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activeadmin_sortable_table-1.2.0 lib/active_admin/sortable_table.rb
activeadmin_sortable_table-1.1.3 lib/active_admin/sortable_table.rb
activeadmin_sortable_table-1.1.2 lib/active_admin/sortable_table.rb
activeadmin_sortable_table-1.1.1 lib/active_admin/sortable_table.rb
activeadmin_sortable_table-1.1.0 lib/active_admin/sortable_table.rb