Skip to content

Commit

Permalink
Use as_json when resource does not respond to to_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Jan 6, 2018
1 parent d9a4b4a commit f38f645
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pragma/rails/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def resource_to_json(resource)
resource_to_json(instance)
end
else
resource.method(:to_hash).arity.zero? ? resource.to_hash : resource.to_hash(options)
if resource.respond_to?(:to_hash)
resource.method(:to_hash).arity.zero? ? resource.to_hash : resource.to_hash(options)
else
resource.as_json(options)
end
end
end
end
Expand Down

0 comments on commit f38f645

Please sign in to comment.