加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-4 – Rails控制台:无法自动加载常量

发布时间:2020-12-16 20:36:04 所属栏目:百科 来源:网络整理
导读:我有一个Customer_ratings模型,允许用户互相留下反馈.网络应用程序正常工作,并收集,存储和显示反馈. 我想通过rails控制台进入并删除一些反馈,但是当我输入Customer_rating.all时,我收到以下错误: LoadError: Unable to autoload constant Customer_rating,e
我有一个Customer_ratings模型,允许用户互相留下反馈.网络应用程序正常工作,并收集,存储和显示反馈.

我想通过rails控制台进入并删除一些反馈,但是当我输入Customer_rating.all时,我收到以下错误:

LoadError: Unable to autoload constant Customer_rating,expected /Users/myapps/app/models/customer_rating.rb to define it

同样,如果我输入Customer_rating [0],我得到:

RuntimeError: Circular dependency detected while autoloading constant Customer_rating

通过我的控制台访问其他表时,我没有这个问题.

什么可能导致问题,为什么这个错误不会禁止Customer_ratings通过网络应用程序正常工作?

解决方法

这似乎是一个混乱的命名约定的情况.

根据Rails命名约定,文件名应在CamelCase中的snake_case和类名中.在您的方案中,文件名应为customer_rating.rb,类名称应为CustomerRating.

进行这些更改后,使用CustomerRating.all(作为更新的类名称为CustomerRating)来获取所有客户评级.不要使用Customer_rating.all.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读