简体   繁体   English

Rails控制台:NameError:未初始化的常量

[英]Rails console: NameError: uninitialized constant

I just added a new model to my app named Collector. 我刚刚在我的应用中添加了一个名为Collector的新模型。

I'm trying to make some data changes using the console on my server: 我正在尝试使用服务器上的控制台进行一些数据更改:

GsCollector.all.each do |gsc|
  coll = Collector.new
  coll.project_id = gsc.project_id
  coll.kind = 'GsCollector'
  coll.optional = gsc.optional
  coll.included = gsc.included
  coll.save
  gsc.collector_id = coll.id
  gsc.save

  gsc.custom_descriptions.each do |cd|
    cd.collector_id = coll.id
    cd.save
  end

  gsc.order_notes.each do |note|
    note.collector_id = coll.id
    note.save
  end
end

But this fails with: 但这失败了:

GsCollector Load (0.3ms)  SELECT `gs_collectors`.* FROM `gs_collectors` 
NameError: uninitialized constant Collector
    from (irb):2:in `block in irb_binding'
    from (irb):1:in `each'
    from (irb):1

What's wrong here? 怎么了 These commands in the console on my dev machine worked fine. 我的开发机器上的控制台中的这些命令运行良好。 I did migrate the database on the server. 我确实在服务器上迁移了数据库。

Run the The command 运行命令

reload!

Or restart your terminals to get good result 或重新启动终端以获得良好的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM