Skip to content

Commit 03501a0

Browse files
committed
Use active record error attribute_names intead errors.keys if available
1 parent fc6875f commit 03501a0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/jsonapi/rails/serializable_active_model_errors.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ def initialize(exposures)
2525
end
2626

2727
def as_jsonapi
28-
@errors.keys.flat_map do |key|
28+
error_keys.flat_map do |key|
2929
@errors.full_messages_for(key).map do |message|
3030
SerializableActiveModelError.new(field: key, message: message,
3131
pointer: @reverse_mapping[key])
3232
.as_jsonapi
3333
end
3434
end
3535
end
36+
37+
private
38+
39+
def error_keys
40+
@errors.respond_to?(:attribute_names) ? @errors.attribute_names : @errors.keys
41+
end
3642
end
3743
end
3844
end

0 commit comments

Comments
 (0)