app/controllers/apicasso/crud_controller.rb in apicasso-0.2.9 vs app/controllers/apicasso/crud_controller.rb in apicasso-0.2.10

- old
+ new

@@ -22,16 +22,19 @@ set_access_control_headers render json: index_json end # GET /:resource/1 + # Common behavior for showing a record, with an addition of + # relation/methods including on response def show set_access_control_headers render json: @object.to_json(include: parsed_include) end # PATCH/PUT /:resource/1 + # Common behavior for an update API endpoint def update authorize_for(action: :update, resource: resource.name.underscore.to_sym, object: @object) if @object.update(object_params) @@ -40,16 +43,17 @@ render json: @object.errors, status: :unprocessable_entity end end # DELETE /:resource/1 + # Common behavior for an destroy API endpoint def destroy authorize_for(action: :destroy, resource: resource.name.underscore.to_sym, object: @object) if @object.destroy - head :no_content + head :no_content, status: :ok else render json: @object.errors, status: :unprocessable_entity end end @@ -155,11 +159,11 @@ end end # Parsing of `paginated_records` with pagination variables metadata def built_paginated - { entries: @records }.merge(pagination_metadata_for(paginated_records)) + { entries: paginated_records }.merge(pagination_metadata_for(paginated_records)) end # All records matching current query and it's total def built_unpaginated { entries: @records, total: @records.size } @@ -168,9 +172,10 @@ # Parsed JSON to be used as response payload, with included relations def include_relations @records = JSON.parse(included_collection.to_json(include: parsed_include)) end + # A way to SQL-include if available for current param[:include] def included_collection if @records.try(:includes, parsed_include).present? @records.includes(parsed_include) else @records