HomePresenter 的未初始化常量
我正在尝试实现一个 HomePresenter 在我的 Pages 控制器的 home 操作中使用:
# 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
我的演示者规格通过,没有错误,但是当我运行服务器并访问 Chrome 中的主页时,我得到:
uninitialized constant ActionController::Caching::Pages::HomePresenter
对于在我的应用程序中,我使用的 IndexPresenters 在命名约定和目录结构方面与此几乎相同,但它们都没有给出此错误。
在这里找到了类似但未答复的帖子:
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
弄清楚了这一点,在这里回答:
控制器名称和演示者命名空间之间的名称冲突
基本上,更改
为
Figured this out, answered it here:
Name conflict between controller name and presenter namespace
Basically, change
to
您可能还需要设置自动加载路径以包含
app/presenters
文件夹。有关如何执行此操作的信息,请参阅 delegate_presenter 的文档。(另外,看看那个宝石 - 它可能会带你去你要去的地方!)
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!)