Sha256: 37165db60ae31eef4ee521d3b0018e29a1344e45c69445d36330587117723277

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 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.assign_attributes(object_params_create)

        if @object.save
          render :new
        else
          redirect_to action: :index
        end
      end

      def edit
        @object ||= collection
      end

      def update
        @object ||= collection
        @object.assign_attributes(object_params_update)

        if @object.save
          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

15 entries across 15 versions & 1 rubygems

Version Path
eivo-rails-0.1.12 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.11 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.10 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.9 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.8 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.7 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.6 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.5 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.4 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.3 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.2 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.1 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.1.0 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.0.6 app/controllers/eivo/concerns/resource.rb
eivo-rails-0.0.5 app/controllers/eivo/concerns/resource.rb