Sha256: 7516dd4d6dcfc785eec70050cc1008b0594d090d115d6ce076fffd0514f99ba1

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

module ActiveAdminVersioning
  module ActiveAdmin
    module ResourceController
      def self.included(base)
        base.before_action(:set_paper_trail_whodunnit)
      end

      def show
        page = params[:page].to_i
        @versions = resource.versions.reorder(id: :desc, created_at: :desc).page(params[:page]).per(1)
        @version_number = page > 0 ? @versions.total_count - (page - 1) : @versions.total_count
        if @versions.any? && @versions[0].next.present?
          set_resource_ivar(@versions[0].next.reify)
        end
        show!
      end

      protected

      def user_for_paper_trail
        if current_user_method && respond_to?(current_user_method)
          public_send(current_user_method).try!(:id)
        else
          t("views.version.unknown_user")
        end
      end

      private

      def current_user_method
        @_current_user_method ||= active_admin_namespace.current_user_method
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_admin_versioning-0.3.0 lib/active_admin_versioning/active_admin/resource_controller.rb