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



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

def index
  @elements = Element.accessible_by(current_ability, :index)
  if params[:page_id].present?
    @elements = @elements.where(page_id: params[:page_id])
  end
  if params[:named].present?
    @elements = @elements.named(params[:named])
  end
  respond_with @elements
end

#showObject

Returns a json object for element



22
23
24
25
26
# File 'app/controllers/alchemy/api/elements_controller.rb', line 22

def show
  @element = Element.find(params[:id])
  authorize! :show, @element
  respond_with @element
end