Search code examples
ruby-on-railsactiverecordrescue

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. This seems too simple -- HELP!


Solution

  • It needed require 'active_record/errors', which I didn't see on any of the examples I found when I googled.