Sha256: 586a2ca7d0e22a8bd02077a210aebed9989eb94eacfba26722ca1e1063b6fae8

Contents?: true

Size: 1.81 KB

Versions: 13

Compression:

Stored size: 1.81 KB

Contents

require 'kuhsaft/page_tree'

module Kuhsaft
  module Cms
    class PagesController < AdminController
      def index
        @pages = Kuhsaft::Page.roots
        respond_with @pages
      end

      def show
        @page = Kuhsaft::Page.find(params[:id])
        respond_with @page
      end

      def new
        @page = Kuhsaft::Page.new
        @page.published ||= Kuhsaft::PublishState::UNPUBLISHED
        respond_with @page
      end

      def create
        @page = Kuhsaft::Page.create(page_params)

        if @page.valid?
          flash[:success] = t('layouts.kuhsaft.cms.flash.success', subject: Kuhsaft::Page.model_name.human)
          respond_with @page, location: kuhsaft.edit_cms_page_path(@page)
        else
          render 'new'
        end
      end

      def edit
        @page = Kuhsaft::Page.find(params[:id])
        @page.published ||= Kuhsaft::PublishState::UNPUBLISHED
        @page.bricks.each { |brick| brick.valid? }
        respond_with @page
      end

      def update
        @page = Kuhsaft::Page.find(params[:id])
        if @page.update_attributes(page_params)
          flash[:success] = t('layouts.kuhsaft.cms.flash.success', subject: Kuhsaft::Page.model_name.human)
          respond_with @page, location: kuhsaft.edit_cms_page_path(@page)
        else
          render 'edit'
        end
      end

      def destroy
        @page = Kuhsaft::Page.find(params[:id])
        @page.destroy
        redirect_to kuhsaft.cms_pages_path
      end

      def sort
        Kuhsaft::PageTree.update(params[:page_tree])
      end

      private

      def page_params
        safe_params = [
          :title, :page_title, :slug, :redirect_url, :url, :page_type, :parent_id,
          :keywords, :description, :published, :position
        ]
        params.require(:page).permit(*safe_params)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
kuhsaft-2.5.0 app/controllers/kuhsaft/cms/pages_controller.rb
qbrick-2.5.0.pre app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.4.3 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.4.2 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.4.1 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.4.0 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.6 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.5 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.4 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.3 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.2 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.1 app/controllers/kuhsaft/cms/pages_controller.rb
kuhsaft-2.3.0 app/controllers/kuhsaft/cms/pages_controller.rb