Skip to content
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

Exclude links without any data #1668

Merged
merged 1 commit into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion lib/active_model_serializers/adapter/json_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ def relationships_for(serializer, requested_associations, options)
# }.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

Expand Down
1 change: 1 addition & 0 deletions lib/active_model_serializers/adapter/json_api/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def as_json
hash[:href] = @href if defined?(@href)
hash[:meta] = @meta if defined?(@meta)

return nil if hash.empty?
hash
end

Expand Down
1 change: 1 addition & 0 deletions test/adapter/json_api/links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LinkAuthorSerializer < ActiveModel::Serializer
link :yet_another do
"http://example.com/resource/#{object.id}"
end
link(:nil) { nil }
end

def setup
Expand Down