Sha256: 503f167d1b36d2c15800ec4ef71671f0998df1c8bf47e5f8c8f15e22fb6ee304

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require_dependency 'comable/admin/application_controller'

module Comable
  module Admin
    class VariantsController < Comable::Admin::ApplicationController
      load_and_authorize_resource :product, class: Comable::Product.name
      load_and_authorize_resource :variant, class: Comable::Variant.name, through: :product

      def index
        @q = @variants.ransack(params[:q])
        @variants = @q.result.includes(:product).page(params[:page]).accessible_by(current_ability).by_newest
      end

      def show
        render :edit
      end

      def new
      end

      def create
        if @variant.save
          redirect_to comable.admin_product_variant_path(@product, @variant), notice: Comable.t('successful')
        else
          flash.now[:alert] = Comable.t('failure')
          render :new
        end
      end

      def edit
      end

      def update
        if @variant.update_attributes(variant_params)
          redirect_to comable.admin_product_variant_path(@product, @variant), notice: Comable.t('successful')
        else
          flash.now[:alert] = Comable.t('failure')
          render :edit
        end
      end

      def destroy
        @variant.destroy
        redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
      end

      private

      def variant_params
        params.require(:variant).permit(
          :price,
          :sku,
          stocks_attributes: [:id, :quantity, :stock_location_id, :_destroy],
          option_values_attributes: [:id, :name]
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comable-backend-0.7.0.beta2 app/controllers/comable/admin/variants_controller.rb