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
21
22
23
24
# 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
  @pages = @pages.includes(*page_includes)
  @pages = @pages.ransack(params[:q]).result

  if params[:page]
    @pages = @pages.page(params[:page]).per(params[:per_page])
  end

  render json: @pages, adapter: :json, root: "pages", meta: 
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


32
33
34
35
36
37
38
39
40
# File 'app/controllers/alchemy/api/pages_controller.rb', line 32

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


46
47
48
49
# File 'app/controllers/alchemy/api/pages_controller.rb', line 46

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