Skip to content

Commit 3b5f245

Browse files
committed
Add support for ignoring nil values in Jbuilder scope
1 parent 9aa3dd9 commit 3b5f245

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/jbuilder.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,15 @@ def _map_collection(collection)
341341
end
342342

343343
def _scope
344-
parent_attributes, parent_formatter, parent_deep_format_keys = @attributes, @key_formatter, @deep_format_keys
344+
parent_attributes, parent_formatter, parent_deep_format_keys, parent_ignore_nil =
345+
@attributes, @key_formatter, @deep_format_keys, @ignore_nil
346+
345347
@attributes = BLANK
346348
yield
347349
@attributes
348350
ensure
349-
@attributes, @key_formatter, @deep_format_keys = parent_attributes, parent_formatter, parent_deep_format_keys
351+
@attributes, @key_formatter, @deep_format_keys, @ignore_nil =
352+
parent_attributes, parent_formatter, parent_deep_format_keys, parent_ignore_nil
350353
end
351354

352355
def _is_collection?(object)

0 commit comments

Comments
 (0)