简体   繁体   English

无法在控制台导轨中加载我的模型

[英]Cannot load my model in console rails

I tried to view what is on my Tasks table and all of the sudden I am now getting a uninitialized constant error. 我试图查看我的Tasks表上的内容,突然之间我现在得到一个uninitialized constant错误。 I cannot think why this is happening. 我想不出为什么会这样。 The page is working fine. 该页面工作正常。 By the way, I do have a task.rb in my model. 顺便说一下,我的模型中有一个task.rb。

server@server:~/www/railsapp/$ rails c production
Running via Spring preloader in process 27137
Loading production environment (Rails 5.1.1)
irb(main):001:0> ActiveRecord::Base.connection.tables
   (0.3ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
=> ["ar_internal_metadata", "schema_migrations", "tasks", "users"]
irb(main):002:0> Task.all
NameError: uninitialized constant Task
    from (irb):2
irb(main):003:0> 

I posted the solution for my problem below 我在下面发布了我的问题的解决方案

I finally found out the solution for the problem. 我终于找到了问题的解决方案。 It was Spring causing the issue. 是春天导致了这个问题。 I provided the link to the StackOverflow question down below. 我在下面提供了StackOverflow问题的链接。

I had to run in the terminal: 我不得不在终端跑:

spring stop

Now when I start my console it can read my models. 现在,当我启动我的控制台时,它可以读取我的模型。

The link I found for solution is here 我找到解决方案的链接就在这里

Create a file task.rb in app/models folder: app/models文件夹中创建一个文件task.rb

app/model/task.rb 应用程序/模型/ task.rb

class Task < ActiveRecord::Base

end

That mean for some reason rails did not load file where your model(class name) live. 这意味着由于某些原因,rails没有加载文件(类名)所在的文件。

If your "page" work I suppose that you change something in application but not restart your production(production work on old code). 如果您的“页面”工作,我认为您在应用程序中更改了某些内容但没有重新启动生产(旧代码的生产工作)。 @Alejandro Montilla ask about changes but you didn answer @Alejandro Montilla询问变化,但你没有回答

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

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