Class: Api::ElementsController

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

Instance Method Summary collapse

Instance Method Details

#indexObject

Returns all elements as json object

You can either load all or only these for :page_id param

If you want to only load a specific type of element pass ?named=an_element_name


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/alchemy/api/elements_controller.rb', line 11

def index
  @elements = Element.not_nested
  # Fix for cancancan not able to merge multiple AR scopes for logged in users
  if cannot? :manage, Alchemy::Element
    @elements = @elements.accessible_by(current_ability, :index)
  end
  if params[:page_id].present?
    @elements = @elements.where(page_id: params[:page_id])
  end
  if params[:named].present?
    @elements = @elements.named(params[:named])
  end
  @elements = @elements.includes(*element_includes)

  render json: @elements, adapter: :json, root: "elements"
end

#showObject

Returns a json object for element


30
31
32
33
34
# File 'app/controllers/alchemy/api/elements_controller.rb', line 30

def show
  @element = Element.where(id: params[:id]).includes(*element_includes).first
  authorize! :show, @element
  respond_with @element
end