Sha256: 18a588a5aacef071d344678c40feb541533be597a4d2e0db56d59b7ddfcdd2b4

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

require "globalize"

module KktShoppe
  class ProductLocalisationsController < ApplicationController

    before_filter { @active_nav = :products }
    before_filter { @product = KktShoppe::Product.find(params[:product_id]) }
    before_filter { params[:id] && @localisation = @product.translations.find(params[:id]) }

    def index
      @localisations = @product.translations
    end

    def new
      @localisation = @product.translations.new
      render :action => "form"
    end

    def create
      if I18n.available_locales.include? safe_params[:locale].to_sym
        I18n.locale = safe_params[:locale].to_sym

        if @product.update(safe_params)
          I18n.locale = I18n.default_locale
          redirect_to [@product, :localisations], :flash => { :notice => t("kkt_shoppe.localisations.localisation_created") }
        else
          render :action => "form"
        end
      else
        redirect_to [@product, :localisations]
      end
    end

    def edit
      render :action => "form"
    end

    def update
      if @localisation.update(safe_params)
        redirect_to [@product, :localisations], :notice => t('kkt_shoppe.localisations.localisation_updated')
      else
        render :action => "form"
      end
    end

    def destroy
      @localisation.destroy
      redirect_to [@product, :localisations], :notice =>  t('kkt_shoppe.localisations.localisation_destroyed')
    end

    private

    def safe_params
      params[:product_translation].permit(:name, :locale, :permalink, :description, :short_description)
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kkt_shoppe-2.0.2 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-2.0.1 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-2.0.0 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-1.3.0 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-1.2.1 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-1.2.0 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-1.1.2 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-1.1.1 app/controllers/kkt_shoppe/product_localisations_controller.rb
kkt_shoppe-1.1.0 app/controllers/kkt_shoppe/product_localisations_controller.rb