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
Prev Previous commit
Next Next commit
Update to match suggested changes
  • Loading branch information
Startouf committed Jul 25, 2017
commit 71679dc2a6e8a5422d0134b5dbeca500a83cda3a
16 changes: 10 additions & 6 deletions lib/jsonapi_errorable/validatable.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
module JsonapiErrorable
module Validatable
# @param relationships: nil [Hash] list of relationships to be serialized as errors
# @param relationships: nil [ Hash or FalseClass ] list of relationships whose errors should be serialized
# Defaults to the deserialized data.relationships of Json:api Payload
# @param record [ ActiveModel ] Object that implements ActiveModel
def render_errors_for(record, relationships: nil)
validation = Serializers::Validation.new(
record,
relationships || deserialized_params.relationships
)

relationships =
if relationships == false
{}
else
relationships || deserialized_params.relationships
end

validation = Serializers::Validation.new(record, relationships)

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