Sha256: 0eb88c99a8df776ba6476ab9029fdab4a6348f0c2dc4708c5072b36d93cefbbb

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8

module ConstructorPages
  class TemplatesController < ApplicationController
    include TreeviewHelper

    movable :template

    before_filter {@roots = Template.roots}

    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 action: :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 action: :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

15 entries across 15 versions & 3 rubygems

Version Path
constructor-pages-0.7.7 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.7.6 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.7.5 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.7.4 app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.7.3 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-core-0.7.3 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-cms-0.7.3 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.7.2 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-core-0.7.2 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-cms-0.7.2 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-core-0.7.1 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.7.0 app/controllers/constructor_pages/templates_controller.rb
constructor-cms-0.7.0 pages/app/controllers/constructor_pages/templates_controller.rb
constructor-pages-0.6.4 app/controllers/constructor_pages/templates_controller.rb
constructor-cms-0.6.4 pages/app/controllers/constructor_pages/templates_controller.rb