Sha256: 77d938408d7a0e9e21d549db86164c53042a612c6dcca655e847e252b87d8e33

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8

module ConstructorPages
  class TemplatesController < ApplicationController
    include TreeviewHelper

    movable :template

    before_filter -> {@templates = Template.all}, only: [:index, :new, :edit, :update, :create]

    def index
      @templates_cache = Digest::MD5.hexdigest(@templates.map{|t| [t.name, t.lft]}.join)
    end

    def new
      @template = Template.new
    end

    def edit
      @template = Template.find(params[:id])
    end

    def create
      @template = Template.new template_params

      if @template.save
        redirect_to templates_url, notice: t(:template_success_added, name: @template.name)
      else
        render :new
      end
    end

    def update
      @template = Template.find params[:id]

      if @template.update template_params
        redirect_to templates_url, notice: t(:template_success_updated, name: @template.name)
      else
        render :edit
      end
    end

    def destroy
      @template = Template.find(params[:id])

      if @template.pages.count == 0
        name = @template.name
        @template.destroy
        redirect_to templates_url, notice: t(:template_success_removed, name: name)
      else
        redirect_to :back, alert: t(:template_error_delete_pages)
      end
    end

    private

    def template_params
      params.require(:template).permit(
          :name,
          :code_name,
          :parent_id,
          :child_id
      )
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
constructor-pages-0.8.15 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.14 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.13 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.12 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.11 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.10 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.8 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.7 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.6 app/controllers/constructor_pages/templates_controller.rb