Internal Server Error 500 gets thrown instead of 404 while trying to access broken picture urls
We found the mistake.
We had an error_controller.rb containing this:
def error_404 @not_found_path = params[:not_found] render template: 'errors/error_404', layout: 'layouts/application', status: 404 end
and we changed it to fix this problem to:
def error_404 @not_found_path = params[:not_found] respond_to do |format| format.html { render template: 'errors/error_404', layout: 'layouts/application', status: 404 } format.all { render nothing: true, status: 404 } end end
Try adding
respond_to :html, :json, :png
and any other necessary formats at the top of your controller. If I'm right, then the problem is that format.all
in the individual controller actions isn't set up to include :png
as one of the formats it responds to.
You will probably also need to add to your config/environment.rb
the following definition and any similar ones:
Mime::Type.register "image/png", :png
See more details here. Basically you need to set up the mime types that you want to respond to. The error message indicates that rails doesn't understand how to render the format png
.