Class: RestEngine::MainController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rest_engine/main_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



30
31
32
33
# File 'app/controllers/rest_engine/main_controller.rb', line 30

def create
  @item = @model.new(request.POST)
  @success = !!@item.save
end

#destroyObject



25
26
27
28
# File 'app/controllers/rest_engine/main_controller.rb', line 25

def destroy
  @item = @model.find(params[:id])
  @success = !!@item.destroy
end

#listObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/rest_engine/main_controller.rb', line 7

def list
  options = {}
  if params[:page]
    page = params[:page].to_i
    page = 1 if page <= 0

    options[:limit] = params[:limit].to_i
    options[:offset] = (page - 1) * options[:limit]
  end
  options[:include] = @associations if @associations

  @items = @model.all(options)
end

#showObject



21
22
23
# File 'app/controllers/rest_engine/main_controller.rb', line 21

def show
  @item = @model.find(params[:id])
end

#updateObject



35
36
37
38
# File 'app/controllers/rest_engine/main_controller.rb', line 35

def update
  @item = @model.find(params[:id])
  @success = !!@item.update_attributes(request.POST)
end