Need some feedback for my pull request

Hello,

I just send a new pull request. You can see it here :
https://github.com/rails/rails/pull/7189. I don't know if there is a
better way to do what I want but it's the solution I found.

Can you check it please?

Thanks!