Skip to content

Commit 51d2c2f

Browse files
authored
Add a keyword parameter to override relationships to be rendered for jsonapi errors
This especially allows to render jsonapi errors without a jsonapi payload (such as GET requests) by passing `relationships: {}`
1 parent a081330 commit 51d2c2f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/jsonapi_errorable/validatable.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module JsonapiErrorable
22
module Validatable
3-
def render_errors_for(record)
4-
validation = Serializers::Validation.new \
5-
record, deserialized_params.relationships
3+
# @param relationships: nil [Hash] list of relationships to be serialized as errors
4+
# @param record [ ActiveModel ] Object that implements ActiveModel
5+
def render_errors_for(record, relationships: nil)
6+
validation = Serializers::Validation.new(
7+
record,
8+
relationships || deserialized_params.relationships
9+
)
10+
611

712
render \
813
json: { errors: validation.errors },

0 commit comments

Comments
 (0)