0

How to catch ActionController::RoutingError when we return missing images on development mode? When i run Rspec and Capybara test it is hard to catch this errors.

  • 2
    I think [this](http://stackoverflow.com/questions/25841377/rescue-from-actioncontrollerroutingerror-in-rails4) may be useful for you. – Mihail Petkov Dec 26 '15 at 14:52

1 Answers1

-1

Catching all exceptions: Add this to application_controller,

  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  rescue_from ActiveRecord::RecordInvalid, :with => :render_500
  rescue_from ActionController::MissingFile, :with => :render_404
  rescue_from ActionController::RoutingError, :with => :render_404
  rescue_from ActionView::TemplateError, :with => :render_500
  rescue_from Errno::ENOENT, :with => :render_404
  rescue_from Errno::EACCES, :with => :render_404

  def render_404
   if Rails.env.production?  
    render :layout=>false,:file => Rails.root.join('public', '404.html'), :status => 404
   else
    raise Exception, I18n.t('str_error')+" - #{error.inspect}"
    #comment the above line and uncomment the below line if you want to custom see error pages instead of error messages in your local
    #render :layout=>false,:file => Rails.root.join('public', '404.html'), :status => 404
   end
  end
Sahil
  • 3,338
  • 1
  • 21
  • 43