Sha256: 22fca9e4a20e0af2b965da140725d67294f1e126fa74af0a8952ec1a204baa76

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module EIVO
  module Concerns
    module Resources
      extend ::ActiveSupport::Concern

      def index
        @objects ||= collection_index
      end

      def show
        @object ||= collection.find(params[:id])
      end

      def new
        @object ||= collection.new
      end

      def create
        @object ||= collection.new(object_params_create)
        if @object.save
          redirect_to action: :index
        else
          render :new
        end
      end

      def edit
        @object ||= collection.find(params[:id])
      end

      def update
        @object ||= collection.find(params[:id])
        if @object.update(object_params_update)
          redirect_to action: :index
        else
          render :edit
        end
      end

      def destroy
        @object ||= collection.find(params[:id])
        @object.destroy

        redirect_to action: :index
      end

    protected
      
      def collection
        raise NotImplementedError
      end

      def collection_index
        collection
      end

      def object_params
        raise NotImplementedError
      end

      def object_params_create
        object_params
      end

      def object_params_update
        object_params
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eivo-rails-0.0.3 app/controllers/eivo/concerns/resources.rb
eivo-rails-0.0.2 app/controllers/eivo/concerns/resources.rb
eivo-rails-0.0.1 app/controllers/eivo/concerns/resources.rb