Sha256: bd60c068ffd29bb28b22a8b64df7fdf963092be3df2a7e797e345698c2f534f1

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

module Tienda
  class VariantsController < ApplicationController

    before_filter { @active_nav = :products }
    before_filter { @product = Tienda::Product.find(params[:product_id]) }
    before_filter { params[:id] && @variant = @product.variants.find(params[:id]) }

    def index
      @variants = @product.variants.ordered
    end

    def new
      @variant = @product.variants.build
      render action: "form"
    end

    def create
      @variant = @product.variants.build(safe_params)
      if @variant.save
        redirect_to [@product, :variants], notice: t('tienda.variants.create_notice')
      else
        render action: "form"
      end
    end

    def edit
      render action: "form"
    end

    def update
      if @variant.update(safe_params)
        redirect_to edit_product_variant_path(@product, @variant), notice: t('tienda.variants.update_notice')
      else
        render action: "form"
      end
    end

    def destroy
      @variant.destroy
      redirect_to [@product, :variants], notice: t('tienda.variants.destroy_notice')
    end

    private

    def safe_params
      params[:product].permit(:name, :permalink, :sku, :default_image_file, :price, :cost_price, :tax_rate_id, :weight, :stock_control, :active, :default)
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tienda-2.1.3 app/controllers/tienda/variants_controller.rb
tienda-2.1.2 app/controllers/tienda/variants_controller.rb
tienda-2.1.1 app/controllers/tienda/variants_controller.rb
tienda-2.1.0 app/controllers/tienda/variants_controller.rb
tienda-2.0.2 app/controllers/tienda/variants_controller.rb
tienda-2.0.1 app/controllers/tienda/variants_controller.rb
tienda-1.1.2 app/controllers/tienda/variants_controller.rb
tienda-1.1.1 app/controllers/tienda/variants_controller.rb
tienda-1.1.0 app/controllers/tienda/variants_controller.rb
tienda-1.0.0 app/controllers/tienda/variants_controller.rb