简体   繁体   English

Rails未定义常量:ActiveRecord :: RecordNotFound

[英]Rails Undefined Constant: 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 . 当我运行它(实际上我运行rake db:migrate )时,出现错误uninitialized constant ActiveRecord::RecordNotFound This seems too simple -- HELP! 这似乎太简单了-帮助!

它需要require 'active_record/errors' ,我在require 'active_record/errors'搜索时发现的所有示例中都没有看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM