Class: RestArea::RestController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- RestArea::RestController
- Includes:
- GetsKlass
- Defined in:
- app/controllers/rest_area/rest_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST.
-
#delete ⇒ Object
DELETE.
-
#index ⇒ Object
GET.
- #show ⇒ Object (also: #edit)
-
#update ⇒ Object
PUT.
Methods included from GetsKlass
Instance Method Details
#create ⇒ Object
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 |
#delete ⇒ Object
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 |
#index ⇒ Object
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 |
#show ⇒ Object 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 |
#update ⇒ Object
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 |