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

StackOverflow https://stackoverflow.com/questions/10109279

  •  30-05-2021
  •  | 
  •  

Question

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

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top