[英]Rails - uninitialized constant Post (NameError)
I have a script in my lib folder called flow.rb This file is run as a background process. 我的lib文件夹中有一个名为flow.rb的脚本。此文件作为后台进程运行。
In my file I am trying to create posts: 在我的文件中,我试图创建帖子:
@post = Post.new
But I get this error 但是我得到这个错误
uninitialized constant Post (NameError)
What is causing this. 是什么原因造成的。 Do I have to import or require activerecord? 我是否需要导入或需要activerecord?
You have two options. 您有两个选择。 Start you script with the rails runner
: 开始你的脚本rails runner
:
rails runner flow.rb
Or require the Rails environment in your script with: 或在脚本中要求使用Rails环境:
require File.expand_path('../config/environment', __FILE__)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.