Sha256: b09bfb4f9549c17e7246d6b7b857a90aac1e5b43811fff3f87dc699b99b59b13

Contents?: true

Size: 887 Bytes

Versions: 10

Compression:

Stored size: 887 Bytes

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

10 entries across 10 versions & 1 rubygems

Version Path
alchemy_cms-3.4.2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.4.1 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.3.3 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.3.2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.4.0 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.4.0.rc1 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.3.1 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.3.0 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.3.0.rc2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.3.0.rc1 app/controllers/alchemy/api/pages_controller.rb