Sha256: 4cfb77b76497752abc22a2a482e77e10c45127d1ab9e60d1659f11c95bc88dac

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

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

12 entries across 12 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.6 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.5 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.4 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.3 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.1 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-4.0.0.beta app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.6.0 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.5.0 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.5.0.rc2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.5.0.rc1 app/controllers/alchemy/api/pages_controller.rb