Search code examples
ruby-on-rails-3rescue

How can Rails automatically rescue from ActiveRecord::RecordNotFound in development mode?


I am using the following piece of code on my ApplicationController :

rescue_from ActiveRecord::RecordNotFound, :with => :not_found

def not_found
  render :nothing => true, :status => :not_found
end

in order make Rails respond with correct status code and not raise an exception in development mode.

I know that how-to-handle-errors-like-404-500-in-rails3 explains how Rails works in production mode. In other words, what I am trying to do in development mode is done without any piece of code in production mode.

How can I make development mode behave like production mode and get rid of the above piece of code?

Note that I am using Rails 3.2.3


Solution

  • Perhaps you want to turn this off?:

    config.consider_all_requests_local       = false
    

    This is set to true in config/environments/development.rb by default.