Sha256: 18db91eb94478f26cf3ce04c62c2e5b59172b920836fb1d4c1ceb629c215d964

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

module Rao
  module ResourcesController::ActsAsListConcern
    extend ActiveSupport::Concern

    def reposition
      @resource = load_resource
      @dropped_resource = load_resource_scope.find(params[:dropped_id])
      @dropped_resource.set_list_position(@resource.position)
      position = @dropped_resource.position < @resource.position ? :before : :after

      label_methods = [:human, :name, :title, :email, :to_s]

      target_resource_label = nil
      label_methods.each do |method_name|
        if @resource.respond_to?(method_name)
          target_resource_label = @resource.send(method_name)
          break
        end
      end

      inserted_resource_label = nil
      label_methods.each do |method_name|
        if @dropped_resource.respond_to?(method_name)
          inserted_resource_label = @dropped_resource.send(method_name)
          break
        end
      end

      redirect_to after_reposition_location, notice: I18n.t("acts_as_list.flash.actions.reposition.inserted_#{position}", target_resource: target_resource_label, inserted_resource: inserted_resource_label)
    end

    private

    def after_reposition_location
      collection_path
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rao-resources_controller-0.0.17.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.16.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.15.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.14.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.13.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.12.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.11.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.10.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.9.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.8.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.7.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.6.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.5.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.4.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb
rao-resources_controller-0.0.3.pre app/concerns/rao/resources_controller/acts_as_list_concern.rb