Rails 未定义常量:ActiveRecord::RecordNotFound

发布于 2024-12-01 18:17:53 字数 421 浏览 4 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两个我 2024-12-08 18:17:53

它需要 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文