Class: Api::PagesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/alchemy/api/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

Returns all pages as json object


9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/alchemy/api/pages_controller.rb', line 9

def index
  # Fix for cancancan not able to merge multiple AR scopes for logged in users
  if can? :edit_content, Alchemy::Page
    @pages = Page.all
  else
    @pages = Page.accessible_by(current_ability, :index)
  end
  if params[:page_layout].present?
    @pages = @pages.where(page_layout: params[:page_layout])
  end
  render json: @pages, adapter: :json, root: :pages
end

#nestedObject

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


28
29
30
31
32
33
34
35
36
# File 'app/controllers/alchemy/api/pages_controller.rb', line 28

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

#showObject

Returns a json object for page

You can either load the page via id or its urlname


42
43
44
45
# File 'app/controllers/alchemy/api/pages_controller.rb', line 42

def show
  authorize! :show, @page
  respond_with @page
end