简体   繁体   中英

Rails console: NameError: uninitialized constant

I just added a new model to my app named 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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