Rails 未定义常量:ActiveRecord::RecordNotFound
我的应用程序控制器中有以下代码:
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
private
def record_not_found
render :text => "404 Not Found", :status => 404
end
end
当我运行它时(实际上我运行rake db:migrate
),我收到错误未初始化常量ActiveRecord::RecordNotFound
。这看起来太简单了——救命!
I have the following code in my Application Controller:
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
private
def record_not_found
render :text => "404 Not Found", :status => 404
end
end
When I run it (actually I run rake db:migrate
) I get the error uninitialized constant ActiveRecord::RecordNotFound
. This seems too simple -- HELP!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它需要
require 'active_record/errors'
,但我在 Google 搜索时发现的任何示例中都没有看到它。It needed
require 'active_record/errors'
, which I didn't see on any of the examples I found when I googled.