Skip to content

Ensure that Jbuilder.encode properly forwards arguments to .new #601

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

Merged

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