nesquena/rabl — pull request #527 by addbrick (2014-02-07 22:34:40+00:00)
Title: Adds exclude_empty_values_in_collections option

This adds `config.exclude_empty_values_in_collections`
This will remove any empty hash returned when building a collection. This is useful when you catch errors in an index.rabl. For instance when trying to be robust about sub-entities that may be missing. When loading a feed of items, if a related entity is not found, the main feed item can be excluded from the list. You could check whether each sub-item exists when building the collection in the controller instead, but then you would not be leveraging the caching per-item in the rabl. To do this in a way that leverages caching while also being robust about bad references, you need this setting.

```
collection @feed_items

node do |feed_item|
begin
partial 'shared/feed/show.json', object: feed_item
rescue ActiveRecord::RecordNotFound => e
nil
end
end
```

**TODO:**
- Add specs that test exclude_empty_values_in_collections is really removing values. I am not sure how to run the specs locally so any help with that would be awesome.