Skip to content

Add a kwarg to override relationships rendered in jsonapi errors #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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: {}`
  • Loading branch information
Startouf authored Jul 25, 2017
commit 51d2c2f5578521ccd8fe4311d2fba471ab9e0a87
11 changes: 8 additions & 3 deletions lib/jsonapi_errorable/validatable.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module JsonapiErrorable
module Validatable
def render_errors_for(record)
validation = Serializers::Validation.new \
record, deserialized_params.relationships
# @param relationships: nil [Hash] list of relationships to be serialized as errors
# @param record [ ActiveModel ] Object that implements ActiveModel
def render_errors_for(record, relationships: nil)
validation = Serializers::Validation.new(
record,
relationships || deserialized_params.relationships
)


render \
json: { errors: validation.errors },
Expand Down