mini_api
Advanced tools
@@ -26,5 +26,9 @@ # frozen_string_literal: true | ||
| else | ||
| { data: serialiable_body(@resource) }.merge(body) | ||
| { data: serialiable_body(@resource).as_json }.merge(body) | ||
| end | ||
| # This is for an problem with ActiveModelSerializer that adds an error | ||
| # attribute when resource is an ActiveModel instance | ||
| body[:data] = body[:data].except('errors') if body[:data]&.key?('errors') | ||
| @controller.render json: body, status: status_code | ||
@@ -44,5 +48,5 @@ end | ||
| return :created if @resource.previously_new_record? | ||
| return :created if previously_new_record? | ||
| return :no_content unless @resource.persisted? | ||
| return :no_content if destroyed? | ||
@@ -62,3 +66,15 @@ :ok | ||
| end | ||
| def previously_new_record? | ||
| return true if @resource.is_a?(ActiveRecord::Base) && @resource.previously_new_record? | ||
| false | ||
| end | ||
| def destroyed? | ||
| return true if @resource.is_a?(ActiveRecord::Base) && !@resource.persisted? | ||
| false | ||
| end | ||
| end | ||
| end |
| # frozen_string_literal: true | ||
| module MiniApi | ||
| VERSION = '0.1.1' | ||
| VERSION = '0.1.2' | ||
| end |
+1
-1
@@ -6,3 +6,3 @@  | ||
| # Mini Api | ||
| A gem to standardize json responses in Rails applications, highly inspired on [Responders](https:github.com/heartcombo/responders) | ||
| A gem to standardize json responses in Rails applications, highly inspired on [Responders](https://github.com/heartcombo/responders) | ||
@@ -9,0 +9,0 @@ ## Table of Contents |