问题
I'm trying to implement a HomePresenter to be used inside the home action of my Pages controller:
# app/controllers/pages_controller.rb
class PagesController < ApplicationController
def home
@presenter = Pages::HomePresenter.new(current_user)
end
...
end
# app/presenters/pages/home_presenter.rb
module Pages
class HomePresenter
def initialize(user)
@user = user
end
...
end
end
My presenter specs pass without errors, but when I run the server and access the home page in Chrome, I get this:
uninitialized constant ActionController::Caching::Pages::HomePresenter
For two other models in my app, I'm using IndexPresenters that are almost identical to this one with regard to naming convention and directory structure, but neither of them gives this error.
Found a similar, yet unanswered post here:
Name conflict between controller name and presenter namespace
Any ideas?
回答1:
Figured this out, answered it here:
Name conflict between controller name and presenter namespace
Basically, change
@presenter = Pages::HomePresenter.new(current_user)
to
@presenter = ::Pages::HomePresenter.new(current_user)
回答2:
You also may want to set your autoload path to include the app/presenters
folder. See the documentation for delegate_presenter on how to do this.
(Also, check out that gem - it may get you where you are going!)
来源:https://stackoverflow.com/questions/7925685/uninitialized-constant-for-homepresenter