Rails未定义常量:ActiveRecord :: RecordNotFound

Jac*_*R-G 2 activerecord ruby-on-rails rescue

我的应用程序控制器中有以下代码:

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
Run Code Online (Sandbox Code Playgroud)

当我运行它(实际上我运行rake db:migrate)我得到错误uninitialized constant ActiveRecord::RecordNotFound.这似乎太简单了 - 帮助!

Jac*_*R-G 7

它需要require 'active_record/errors',我在google搜索时找到的任何例子都没有看到.