port PR rails/rails#7416