Module: Api::ResourcesController::Base::RestActions
- Extended by:
- ActiveSupport::Concern
- Included in:
- Api::ResourcesController::Base
- Defined in:
- app/controllers/api/resources_controller/base.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/api/resources_controller/base.rb', line 41 def create respond_to do |format| if @resource.save format.json { render json: serialize_resource(@resource), status: :created } else format.json { render json: { errors: serialize_errors(@resource.errors) }, status: 422 } end end end |
#delete ⇒ Object
68 69 70 71 72 73 |
# File 'app/controllers/api/resources_controller/base.rb', line 68 def delete @resource.delete respond_to do |format| format.json { render json: serialize_resource(@resource) } end end |
#destroy ⇒ Object
61 62 63 64 65 66 |
# File 'app/controllers/api/resources_controller/base.rb', line 61 def destroy @resource.destroy respond_to do |format| format.json { render json: serialize_resource(@resource) } end end |
#index ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/api/resources_controller/base.rb', line 25 def index respond_to do |format| format.json { render json: serialize_collection(@collection) } end end |
#show ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/api/resources_controller/base.rb', line 31 def show respond_to do |format| if @resource.nil? format.json { render json: { error: "Couldn't find #{resource_class} with ID=#{params[:id]}" }, status: :not_found } else format.json { render json: serialize_resource(@resource), status: :ok } end end end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/api/resources_controller/base.rb', line 51 def update respond_to do |format| if @resource.update_attributes(permitted_params) format.json { render json: serialize_resource(@resource) } else format.json { render json: { errors: serialize_errors(@resource.errors) }, status: 422 } end end end |