Closed NullVoxPopuli closed 7 years ago
Not sure I'm understanding the situation. The fields
option can be either not supplied, or a hash of arrays of symbols. Could you provide a full stack trace along with the faulty code?
yup, here is a trace:
Failure/Error:
# the json assignment is line 12
json = JSONAPI::Serializable::Renderer.render(
data,
include: params[:include],
fields: params[:fields],
class: SerializableUser
)
NoMethodError:
undefined method `each_with_object' for nil:NilClass
# /home/lprestonsegoiii/.gem/ruby/2.4.0/gems/jsonapi-renderer-0.1.2/lib/jsonapi/renderer/document.rb:53:in `_symbolize_fields'
# /home/lprestonsegoiii/.gem/ruby/2.4.0/gems/jsonapi-renderer-0.1.2/lib/jsonapi/renderer/document.rb:12:in `initialize'
# /home/lprestonsegoiii/.gem/ruby/2.4.0/gems/jsonapi-renderer-0.1.2/lib/jsonapi/renderer.rb:23:in `new'
# /home/lprestonsegoiii/.gem/ruby/2.4.0/gems/jsonapi-renderer-0.1.2/lib/jsonapi/renderer.rb:23:in `render'
# /home/lprestonsegoiii/.gem/ruby/2.4.0/gems/jsonapi-serializable-0.1.3/lib/jsonapi/serializable/renderer.rb:24:in `render'
# /home/lprestonsegoiii/.gem/ruby/2.4.0/gems/jsonapi-serializable-0.1.3/lib/jsonapi/serializable/renderer.rb:8:in `render'
# ./app/controllers/concerns/jsonapi_endpoints.rb:12:in `render_data'
I'm manually invoking jsonapi-rb
, just for fun for some benchmarks of various scenarios -- so it's totally possible I messed something up.
Here is the calling code's context if you're curious: https://github.com/NullVoxPopuli/rails-NPlusOneTests/blob/master/app/controllers/concerns/jsonapi_endpoints.rb#L12
Right, so what's happening is that params.fetch(:fields, {})
will result in nil
if params[:fields]
is explicitly set to nil
. I'd accept a PR to fix that (basically replacing the params.fetch(:fields, {})
in this line with params[:fields] || {}
.
NOICE, @beauby
is this intentional?
above is the workaround.
without I get the error: