Sha256: 75bd4517ffc56b06c02fdeba21008ace82f58434573b3dab3785e166900bca9e

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 KB

Contents

require_dependency "pages_cms/application_controller"

module PagesCms
  class PagesController < ApplicationController

    def show
      @site = current_site
      page  = @site.pages.find_by_slug(params[:slug])
      page_setup(page)
    end

    def home
      @site = current_site
      page  = @site.pages.find_by_slug('home')
      page_setup(page)
    end

    private
      def page_setup(page)
        if page != nil
          @page = page
          @articles = current_site.articles.published
          filter_params(params).each do |search, result|
            @articles = @articles.public_send(search, result) if result.present?
          end

          sidebar = @page.sidebar
          if sidebar && sidebar.show && sidebar.use_instead.nil?
            @sidebar = sidebar
          elsif sidebar && !sidebar.show
            @sidebar = false
          elsif sidebar && !sidebar.use_instead.nil?
            @sidebar = Sidebar.find(sidebar.use_instead)
          else
            @sidebar = false
          end

          if @page.sliders && @page.sliders.any?
            @sliders = @page.sliders.order(:order)
          else
            @sliders = false
          end
          render template: 'pages_cms/pages/show'
        else
          # flash[:danger] = 'could not find page'
          # redirect_to '/'
        end
      end

      def filter_params(params)
        params.slice(:search)
      end

      def current_site
        Account.find(params[:account])
      end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pages_cms-2.1.1 app/controllers/pages_cms/pages_controller.rb
pages_cms-2.1.0 app/controllers/pages_cms/pages_controller.rb
pages_cms-2.0.1 app/controllers/pages_cms/pages_controller.rb
pages_cms-2.0.0 app/controllers/pages_cms/pages_controller.rb
pages_cms-1.2.3 app/controllers/pages_cms/pages_controller.rb
pages_cms-1.2.2 app/controllers/pages_cms/pages_controller.rb
pages_cms-1.2.1 app/controllers/pages_cms/pages_controller.rb
pages_cms-1.2.0 app/controllers/pages_cms/pages_controller.rb