Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Undefined method render for class: JSONAPI::Serializable::Render #13

Open
mihaimuntenas opened this issue Dec 1, 2017 · 7 comments
Open

Comments

@mihaimuntenas
Copy link

Trying to use with Hanami (1.1.0) and encountered the following error:

NoMethodError: undefined method render' for JSONAPI::Serializable::Renderer:Class /home/mihai/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/jsonapi-hanami-0.1.2/lib/jsonapi/hanami/rendering.rb:28:in _jsonapi_render_success'
/home/mihai/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/jsonapi-hanami-0.1.2/lib/jsonapi/hanami/rendering.rb:21:in _jsonapi_render' /home/mihai/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/jsonapi-hanami-0.1.2/lib/jsonapi/hanami/rendering.rb:12:in block (2 levels) in included'

Problem seems to be that JSONAPI::Serializable::Renderer#render is an instance method not a class one in https://github.com/jsonapi-rb/jsonapi-serializable/blob/cabf10e319a3ce8e52412d6f435fdca458ac2b56/lib/jsonapi/serializable/renderer.rb#L38 (also in master) and is used as a class method in

self.body = JSONAPI::Serializable::Renderer.render(@_jsonapi[:data],
(also in master).

Maybe an oversight in Renderer class, missing something like this:

def self.render(resources, options = {})
  self.new.render(resources, options)
end

Gems versions:
jsonapi-hanami: 0.1.2
jsonapi-renderer: 0.2.0
jsonapi-serializable: 0.3.0

@beauby
Copy link
Member

beauby commented Dec 1, 2017

@mihaimuntenas Thanks for reporting this – it should be fixed by using master (gem 'jsonapi-hanami', github: 'jsonapi-rb/jsonapi-hanami'). I'll try to publish the new version soon.

@HarryBar
Copy link

Hi, i have still the same issue. Could you fix that please so i can remove my monkey patch. Thanks

@wuarmin
Copy link

wuarmin commented Feb 7, 2018

@beauby
If have the same problems. After changing Gemfile as you mentioned, I get following error

/home/armin/.devel/essence/essence_backend/lib/essence_backend/serializers/serializable_dwh_fiscal_year.rb:3:in `<class:SerializableFrFilter>': undefined method `key_format' for SerializableFrFilter:Class (NoMethodError)
	from /home/armin/.devel/essence/essence_backend/lib/essence_backend/serializers/serializable_dwh_fiscal_year.rb:1:in `<top (required)>'
	from /home/armin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-utils-1.1.1/lib/hanami/utils.rb:52:in `require_relative'
	from /home/armin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-utils-1.1.1/lib/hanami/utils.rb:52:in `block in require!'
	from /home/armin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-utils-1.1.1/lib/hanami/utils.rb:90:in `each'
	from /home/armin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-utils-1.1.1/lib/hanami/utils.rb:90:in `for_each_file_in'
	from /home/armin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-utils-1.1.1/lib/hanami/utils.rb:52:in `require!'
	from /home/armin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-1.1.0/lib/hanami/components/components.rb:67:in `block (2 levels) in <module:Components>'

Here's one of my serializers:

class SerializableFrFilter < JSONAPI::Serializable::Resource
  extend JSONAPI::Serializable::Resource::KeyFormat
  
  key_format ->(key) { key.to_s.dasherize }

  type 'filters'

  attribute :standard_company
  attribute :standard_accounting_area
  attribute :dynamic_period


  has_many :accounting_areas do
    linkage always: true
    data do
      @object.accounting_areas&.map do |id|
        DwhProfitcenter.new(id: id)
      end
    end
  end

end

Serializing was working before I changed the Gemfile

thx and best regards

@bradrobertson
Copy link

I just hit this same problem also. Is this fix going to be released?

@nomanurrehman
Copy link

Any updates on this? Because I am stuck at the same issue.

@Quintasan
Copy link

@beauby Do you need help with maintaining this?

@beauby
Copy link
Member

beauby commented Apr 5, 2019

@Quintasan Yes, definitely. It wouldn't take much work, as @dawidof is already maintaining the base gems, so it would just be a matter of maintaining the Hanami integration. Please shoot me an email if you are still interested – I could provide general advice and explain various choices.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants