[英]uninitialized constant ActiveRecord
2.0.0-p247 :006 > load './app/models/user.rb'
NameError: uninitialized constant ActiveRecord
from /home/action/iAuth/app/models/user.rb:1:in `<top (required)>'
from (irb):6:in `load'
from (irb):6
from /home/action/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
Below is my User Model
.下面是我的User Model
。
class User < ActiveRecord::Base
end
When i try to load my user.rb in my irb
, i get the above error.当我尝试user.rb in my irb
,我得到了上述错误。
start your irb
session with开始你的irb
会话
rails console
and not:并不是:
irb
rails console
would load your rails
environment and your model for you, so you can do things like: rails console
会为您加载您的rails
环境和模型,因此您可以执行以下操作:
User.all
or User.new
without loading the class
as it has been preloaded by rails console
already User.all
或User.new
不加载class
,因为它已经由rails console
预加载
there's another case.还有一个案例。
if you are using mongoid ( mongo db adapter) , and you have to make sure in config/application.rb
, you must require activerecord:如果您使用的是 mongoid(mongo db 适配器),并且您必须确保在config/application.rb
中,您必须需要 activerecord:
require "active_model/railtie"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.