Sha256: 9ff86bf16abdf9d96978f98ae4b5e7518c1c5df9775c3946cca32ea407e606e9

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

# encoding: utf-8

module ConstructorPages
  class TemplatesController < ApplicationController
    include TreeviewHelper

    movable :template

    before_filter -> {@roots = Template.roots}, only: [:new, :edit]

    def index
      @templates = Template.all
      @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

6 entries across 6 versions & 1 rubygems

Version Path
constructor-pages-0.8.5 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.4 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.3 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.2 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.1 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.8.0 app/controllers/constructor_pages/templates_controller.rb