Class: Iron::Api::ContentController

Inherits:
BaseController
  • Object
show all
Includes:
CursorPagination
Defined in:
app/controllers/iron/api/content_controller.rb

Constant Summary

Constants included from CursorPagination

Iron::Api::CursorPagination::DEFAULT_PER_PAGE, Iron::Api::CursorPagination::MAX_PER_PAGE

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/iron/api/content_controller.rb', line 23

def create
  @entry = @content_type.entries.build
  @entry.route = params[:route] if params.key?(:route)
  @entry.assign_content(content_params)

  if @entry.save
    render :show, status: :created, location: api_content_url(handle: @content_type.handle, id: @entry.id)
  else
    render json: @entry.content_errors, status: :unprocessable_entity
  end
end

#destroyObject



46
47
48
49
# File 'app/controllers/iron/api/content_controller.rb', line 46

def destroy
  @entry.destroy!
  head :no_content
end

#indexObject



11
12
13
14
15
16
17
18
# File 'app/controllers/iron/api/content_controller.rb', line 11

def index
  if params.key?(:route)
    @entry = @content_type.entries.find_by!(route: params[:route])
    render :show
  else
    @collection = paginate(@content_type.entries)
  end
end

#showObject



20
21
# File 'app/controllers/iron/api/content_controller.rb', line 20

def show
end

#updateObject



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/iron/api/content_controller.rb', line 35

def update
  @entry.route = params[:route] if params.key?(:route)
  @entry.assign_content(content_params)

  if @entry.save
    render :show
  else
    render json: @entry.content_errors, status: :unprocessable_entity
  end
end