mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Exclude links without any data
This commit is contained in:
parent
a1826186e5
commit
87bffef945
@ -464,7 +464,8 @@ module ActiveModelSerializers
|
||||
# }.reject! {|_,v| v.nil? }
|
||||
def links_for(serializer)
|
||||
serializer._links.each_with_object({}) do |(name, value), hash|
|
||||
hash[name] = Link.new(serializer, value).as_json
|
||||
result = Link.new(serializer, value).as_json
|
||||
hash[name] = result if result
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -71,6 +71,7 @@ module ActiveModelSerializers
|
||||
hash[:href] = @href if defined?(@href)
|
||||
hash[:meta] = @meta if defined?(@meta)
|
||||
|
||||
return nil if hash.empty?
|
||||
hash
|
||||
end
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ module ActiveModelSerializers
|
||||
link :yet_another do
|
||||
"http://example.com/resource/#{object.id}"
|
||||
end
|
||||
link(:nil) { nil }
|
||||
end
|
||||
|
||||
def setup
|
||||
|
||||
Loading…
Reference in New Issue
Block a user