Question

I user namespace to create some module in Rails. It works fine in controllers, models, but something is wrong with presenters which are in a presenters path.

This is one of presenters, without namespace:

class MainPresenter < Struct.new(:main, :current_user)
  extend Ext::CollectionPresenter

  def as_json
    {
      something: SomeNamespace::SomePresenter(main.something)
    }
  end

end

And this is the presenter in presenters/some_namespace/some_presenter.rb

class SomeNamespace::SomePresenter < Struct.new(:something, :options)
  extend Ext::CollectionPresenter

  def as_json
    # some hash here
  end

end

I get undefined method 'SomePresenter' for SomeNamespace:Module error. What could be the problem.

Était-ce utile?

La solution

SomePresenter is a class and you are using it as a method. Hence, the error. Use it as below :

something: SomeNamespace::SomePresenter.new(main.something)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top