3

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?

Community
  • 1
  • 1
rickyrickyrice
  • 577
  • 3
  • 14
  • Is there any reason you are defining your class under app/presenters/pages/home_presenter.rb ? Which version of rails are you using? Why don't you make use of lib directory? – nkm Oct 28 '11 at 07:30
  • 1
    this is rails 3.1.1. I guess that directory structure just seemed logical to me. Could you explain why using lib/ would be better? – rickyrickyrice Oct 28 '11 at 17:24

2 Answers2

3

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)
Community
  • 1
  • 1
rickyrickyrice
  • 577
  • 3
  • 14
0

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!)

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60