在控制器中找不到命名空间内的Ruby on Rails模型 [英] Ruby on Rails model inside namespace can't be found in controller

查看:77
本文介绍了在控制器中找不到命名空间内的Ruby on Rails模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Rails的新手,无法解决这个问题...

I'm new to rails and can't figure out this issue...

我有一个控制器

Admin::Blog::EntriesController

在app/controllers/admin/blog/entries_controller.rb中定义

defined in app/controllers/admin/blog/entries_controller.rb

我有一个名为

Blog::Entry

在app/model/blog/entry.rb中定义

defined in app/model/blog/entry.rb

当我尝试从控制器访问我的模型时,我从此行得到一个"uninitialized constant Admin::Blog::EntriesController::Blog":

When I try to access my model from the controller, I get a "uninitialized constant Admin::Blog::EntriesController::Blog" from this line:

@blog_entries = Blog::Entry.find(:all)

很显然,它找不到正确的名称空间,这很奇怪,因为根据我所读的内容,我已将模型以正确的语法放置在正确的文件夹中.

Clearly it is not finding the namespace correctly which is odd because according to what I have read, I have placed my model in the correct folder with the correct syntax.

关于如何解决此问题的任何想法?

Any ideas on how I can fix this?

谢谢

推荐答案

尝试:

@blog_entries = ::Blog::Entry.find(:all)

当前正在寻找错误的课程.在Blog之前使用::会强制其从顶层查看.

It's currently looking for the wrong class. Using :: before Blog will force it to look from the top level.

这篇关于在控制器中找不到命名空间内的Ruby on Rails模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆