Sha256: 368667fb667d2564d2d62c11d296039396f7a6820d028ef46c703d2b36a1b36a

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module EIVO
  module Concerns
    module Resource
      extend ::ActiveSupport::Concern

      def show
        @object ||= collection
      end

      def new
        @object ||= collection.new
      end

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

      def edit
        @object ||= collection
      end

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

      def destroy
        @object ||= collection

        @object.destroy
        redirect_to action: :index
      end

    protected
      
      def collection
        raise NotImplementedError
      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/resource.rb
eivo-rails-0.0.2 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.0.1 app/controllers/eivo/concerns/resource.rb