jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
321 stars 63 forks source link

Upgrading from 0.3.1 to 0.4.0 breaks Renderer #105

Open austinh opened 5 years ago

austinh commented 5 years ago

Hello, I recently tried to upgrade jsonapi-rails from 0.3.1 to 0.4.0 and I get the following error anywhere I call JSONAPI::Serializable::Renderer.new with the exact same params as before:

no implicit conversion of nil into Hash

Note: I am also using this in conjunction with https://github.com/jsonapi-suite/jsonapi_compliable

amaierhofer commented 5 years ago

Where exactly does this error occur? I had troubles too because I was overriding jsonapi_pagination, returning nil for for non index actions. Version 0.3.1 accepted nil return values but 0.4.0 did not. The stacktrace I got was as follows

TypeError: no implicit conversion of nil into Hash
    jsonapi-rails (0.4.0) lib/jsonapi/rails/renderer.rb:28:in `merge!'
ferrisoxide commented 4 years ago

Seems to be the case. I had the same issue (no implicit conversion of nil into Hash) and had to return an empty hash in jsonapi_pagination on non-index/non-paginated data. Thanks @amaierhofer.

jerko-culina commented 4 years ago

I have same issue too. Below is more details: Rails 5.2.4.2

    28: def render_data_japi(data, opts)
 => 29:   binding.pry
    30:   render opts.merge(
    31:     jsonapi: data,
    32:     class: serializable_class
    33:   )
    34: end

[1] pry(#<Api::V2::TranslationsController>)> render opts.merge(
[1] pry(#<Api::V2::TranslationsController>)*   jsonapi: data,
[1] pry(#<Api::V2::TranslationsController>)*   class: serializable_class
[1] pry(#<Api::V2::TranslationsController>)*     )
I, [2020-05-07T04:07:03.451683 #77626]  INFO -- : Completed JSON API rendering (12.8ms)
NoMethodError: undefined method `[]' for Api::V2::SerializableTranslation:Class
from .../.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/jsonapi-serializable-0.3.1/lib/jsonapi/serializable.rb:27:in `resource_for'
[2] pry(#<Api::V2::TranslationsController>)>