gpt4 book ai didi

ruby-on-rails-4 - Rails 控制台 : Unable to autoload constant

转载 作者:行者123 更新时间:2023-12-02 09:32:21 25 4
gpt4 key购买 nike

我有一个 Customer_ ratings 模型,允许用户互相留下反馈。 Web 应用程序运行正常,并且收集、存储和显示反馈。

我想通过 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命名约定,文件名应为 snake_caseCamelCase 中的类名 。在您的场景中,文件名应为 customer_rating.rb类名应该是 CustomerRating .

进行这些更改后,请使用 CustomerRating.all (更新后的类名称为 CustomerRating )以获取所有客户评级。 请勿使用 Customer_rating.all .

关于ruby-on-rails-4 - Rails 控制台 : Unable to autoload constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22773819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com