Sha256: 458b095c18f33f3554ce9af96c9fad63015d9495c6e592c3396a3160c490d213

Contents?: true

Size: 755 Bytes

Versions: 5

Compression:

Stored size: 755 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]
        @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]) ||
              Page.find_by(urlname: params[:urlname]) ||
              raise(ActiveRecord::RecordNotFound)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-3.1.0.beta5 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.1.0.beta4 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.1.0.beta3 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.1.0.beta2 app/controllers/alchemy/api/pages_controller.rb
alchemy_cms-3.1.0.beta1 app/controllers/alchemy/api/pages_controller.rb