Sha256: fce3b9c6f75f3e55019477c06012dae27f59ccb93ded98312fd5bb06cf10bd55

Contents?: true

Size: 617 Bytes

Versions: 7

Compression:

Stored size: 617 Bytes

Contents

# frozen_string_literal: true

module Maquina
  module Edit
    extend ActiveSupport::Concern

    included do
      def edit(&block)
        @resource ||= begin
          scope = resource_class.all
          scope = authorized_scope(scope) if policy_class.present?
          scope = yield(scope) if block.present?

          resource = scope.find_by!(find_by_param => params[:id])

          authorize! resource, with: policy_class if policy_class.present?

          resource
        end

        respond_to do |format|
          format.html
        end
      end
      alias_method :edit!, :edit
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
maquina-0.7.2 app/controllers/concerns/maquina/edit.rb
maquina-0.7.1 app/controllers/concerns/maquina/edit.rb
maquina-0.5.2 app/controllers/concerns/maquina/edit.rb
maquina-0.5.1 app/controllers/concerns/maquina/edit.rb
maquina-0.4.0 app/controllers/concerns/maquina/edit.rb
maquina-0.3.0 app/controllers/concerns/maquina/edit.rb
maquina-0.2.5 app/controllers/concerns/maquina/edit.rb