Sha256: 8a4a1d6c57646c1f4995810dcb8a5098cd384af3796a9e1998b9524f9a591b03

Contents?: true

Size: 992 Bytes

Versions: 3

Compression:

Stored size: 992 Bytes

Contents

module ResourcesController
  module AwesomeNestedSetConcern
    extend ActiveSupport::Concern

    def reposition
      @resource = load_resource
      @dropped_resource = resource_class.find(params[:dropped_id])
      @dropped_resource.move_to_right_of(@resource)

      label_methods = [:human, :name, :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 collection_path, notice: I18n.t("awesome_nested_set.flash.actions.reposition.notice", target_resource: target_resource_label, inserted_resource: inserted_resource_label)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails-add_ons-3.0.0.pre1 app/concerns/resources_controller/awesome_nested_set_concern.rb
rails-add_ons-2.2.1 app/concerns/resources_controller/awesome_nested_set_concern.rb
rails-add_ons-2.2.0 app/concerns/resources_controller/awesome_nested_set_concern.rb