Fix bug displaying nil for relationship link href

When using the relationship link with a block, calling "meta" without "href", e.g.
has_one :bio do
  link :related do
    meta id: 1
  end
end

results in in a nil "href", e.g.
{ links: { posts: { related: { href: nil, meta: { id: 1 } }  } } }.
According to JSONAPI, we should be able to use meta without href
(http://jsonapi.org/format/#document-links).
This commit is contained in:
Yohan Robert
2016-02-10 21:38:30 +01:00
parent 2b673634d9
commit 3cbc0541c1
3 changed files with 45 additions and 23 deletions

View File

@@ -28,8 +28,9 @@ module ActiveModel
def as_json
return @value if @value
hash = { href: @href }
hash.merge!(meta: @meta) if @meta
hash = {}
hash[:href] = @href if @href
hash[:meta] = @meta if @meta
hash
end