문제

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.

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top