Class: RestArea::RestController

Inherits:
ApplicationController show all
Includes:
GetsKlass
Defined in:
app/controllers/rest_area/rest_controller.rb

Instance Method Summary collapse

Methods included from GetsKlass

#get_klass, #test_class

Instance Method Details

#createObject

POST



27
28
29
30
31
32
33
34
# File 'app/controllers/rest_area/rest_controller.rb', line 27

def create
  object = @klass.new(params[@root.to_sym])
  if object.save
    render json: object, root:@root
  else
    render_errors(object)
  end
end

#deleteObject

DELETE



47
48
49
50
51
52
53
54
# File 'app/controllers/rest_area/rest_controller.rb', line 47

def delete
  object = @resource.find(params[:id])
  if object.destroy
    render json: object, root:@root
  else
    render_errors(object)
  end
end

#indexObject

GET



13
14
15
16
17
18
19
# File 'app/controllers/rest_area/rest_controller.rb', line 13

def index
  if @serializer
    render json: @klass.all, each_serializer: @serializer, root:@roots
  else
    render json:{ @roots => @klass.all }.to_json(root:false)
  end
end

#showObject Also known as: edit



21
22
23
# File 'app/controllers/rest_area/rest_controller.rb', line 21

def show
  render json: @resource.find(params[:id]), root: @root
end

#updateObject

PUT



37
38
39
40
41
42
43
44
# File 'app/controllers/rest_area/rest_controller.rb', line 37

def update
  object = @resource.find(params[:id])
  if object.update_attributes(params[@root.to_sym])
    render json: object, root:@root
  else
    render_errors(object)
  end
end