Skip to content

Conversation

flavorjones
Copy link
Member

@flavorjones flavorjones commented Aug 12, 2025

The initializer previously accepted an options hash, but now takes kwargs. So the encode method also needs to accept (and forward) kwargs.

Without this change, existing code like this:

Jbuilder.encode(ignore_nil: true) do |json|
  # ...
end

raises an exception. The test I've added here fails with:

Error:
JbuilderTest#test_encode_forwards_options_to_new:
ArgumentError: wrong number of arguments (given 1, expected 0)
    lib/jbuilder.rb:16:in 'initialize'
    lib/jbuilder.rb:32:in 'Class#new'
    lib/jbuilder.rb:32:in 'Jbuilder.encode'
    test/jbuilder_test.rb:941:in 'block in <class:JbuilderTest>'

Fixes #602

The initializer previously accepted an options hash, but now takes
kwargs. So the encode method also needs to accept (and forward)
kwargs.
@rafaelfranca rafaelfranca merged commit 2400fd9 into rails:main Aug 12, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v2.14.0: Jbuilder.encode keyword arguments are broken.
2 participants