Sha256: 73e007428b8596f0bbeb8dd4a71ebe00033f33a1e516406e8a2e9818f61be4d1

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Alchemy
  class Api::PagesController < Api::BaseController
    before_action :load_page, only: [:show]

    # Returns all pages as json object
    #
    def index
      @pages = Page.accessible_by(current_ability, :index)
      if params[:page_layout].present?
        @pages = @pages.where(page_layout: params[:page_layout])
      end
      respond_with @pages
    end

    # Returns all pages as nested json object for tree views
    #
    # Pass a page_id param to only load tree for this page
    #
    # Pass elements=true param to include elements for pages
    #
    def nested
      @page = Page.find_by(id: params[:page_id]) || Language.current_root_page

      render json: PageTreeSerializer.new(@page,
        ability: current_ability,
        user: current_alchemy_user,
        elements: params[:elements],
        full: true)
    end

    # Returns a json object for page
    #
    # You can either load the page via id or its urlname
    #
    def show
      authorize! :show, @page
      respond_with @page
    end

    private

    def load_page
      @page = Page.find_by(id: params[:id]) ||
              Language.current.pages.find_by(
                urlname: params[:urlname],
                language_code: params[:locale] || Language.current.code
              ) ||
              raise(ActiveRecord::RecordNotFound)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-4.0.6 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.5 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.4 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.3 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.1 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.0 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.0.rc2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.0.rc1 app/controllers/alchemy/api/pages_controller.rb