[英]Rails 3 uninitialized constant ActiveRecord::RecordInvalid
application_controller.rb应用控制器.rb
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordInvalid, :with => :error_render_method
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
def error_render_method
end
def record_not_found
end
end
When I run rspec
I get this error:当我运行rspec
此错误:
uninitialized constant ActiveRecord::RecordInvalid (NameError)
I have googled and found that some people add require 'active_record/errors'
to that file, yet when I do the error still persist.我用require 'active_record/errors'
搜索,发现有些人向该文件添加了require 'active_record/errors'
,但是当我这样做时,错误仍然存在。
I am using rails (3.2.9)
我正在使用rails (3.2.9)
I got the same problem when I started Unicorn.我在启动 Unicorn 时遇到了同样的问题。
I solved it by just quoting the constant "ActiveRecord::RecordInvalid"
.我通过引用常量"ActiveRecord::RecordInvalid"
来解决它。 (Not naked constant ActiveRecord::RecordInvalid
.) (不是裸常量ActiveRecord::RecordInvalid
。)
I don't know the reason but it seemed like ActiveRecord::RecordInvalid
hadn't loaded when starting Unicorn.我不知道原因,但似乎在启动 Unicorn 时没有加载ActiveRecord::RecordInvalid
。
这似乎已在 Rails 4.0 和 4.1 之间修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.