H
H
Hash Hash2015-12-23 19:32:10
Ruby on Rails
Hash Hash, 2015-12-23 19:32:10

How to catch ActionController::RoutingError in Rails when rendering images in development?

There is an application in which old images are constantly cleared. When displaying items with removed images, ActionController::RoutingError pops up, which are difficult to catch when testing.
How to catch ActionController::RoutingError when rendering images in Rails and return default instead of missing images?
Exceptions themselves occur during tests, and it is very difficult to catch them by simply catching exceptions. Used by Rspec and Capybara.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Sidorov, 2015-12-24
@morr

From rails, in general, no way, because. images in production should be served by nginx. Rails has a production setting that forcibly disables static feedback

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_files = false

If, for some reason, you still give the static rails, which is categorically wrong, then you can make an exception interceptor in the ApplicationController
and in it to check if the url of the image is or not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question