Fix undefined method `ref' for nil:NilClass for bad accept headers

One commit for fixing:
Bad HTTP_ACCEPT can cause request.formats to return an array with nil

https://github.com/rails/rails/pull/10965

Full details at link above.