gpt4 book ai didi

ruby-on-rails - 为什么 irb 返回 NameError : uninitialized constant for all objects in the database?

转载 作者:行者123 更新时间:2023-12-04 03:39:31 26 4
gpt4 key购买 nike

我正在构建一个问答应用程序,我已经成功地为我的数据库播种,并且可以看到在我的浏览器和服务器日志中以及之前在 irb 中创建了对象。现在,当我去尝试检查 irb 中的一个对象时,对于我给它的每个对象,irb 返回“NameError:未初始化的常量”。例如:

2.0.0-p481 :001 > user = User.find(1)
NameError: uninitialized constant User
from (irb):1
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :002 > question = Question.find(1)
NameError: uninitialized constant Question
from (irb):2
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :003 > user = User.find
NameError: uninitialized constant User
from (irb):3
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :004 > user = User.new
NameError: uninitialized constant User
from (irb):4
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'

我是编程新手,所以如果有人能解释为什么会发生这种情况,我将不胜感激!

最佳答案

当您需要 rails console(或简称为 rails c)时,您似乎正在运行 irb

关于ruby-on-rails - 为什么 irb 返回 NameError : uninitialized constant for all objects in the database?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26243791/

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