While working on an app where I had to manipulate a URL after its creation I found that some URLs weren't affected by my change. What I did was to alias_method_chain the UrlHelper#url_for method. If I used link_to with a hash or an object, my modifications where applied whereas with a named route path it seemed to just ignore it.
The problem is that link_to, when used with a string (a named route call generates a string), uses the string directly as its href instead of passing it to url_for.
Since url_for has the same behavior for strings anyway, it makes sense to remove it from link_to. This ensures that all URLs are generated in the same place.
I've also moved the :back option to url_for to have all the URL generation functionality encapsulated in url_for and have link_to focus solely on the creation of the actual link tag. Plus, I've changed the order of the case when because I think with modern Rails applications, named routes (and therefore strings) are the preferred option. This might give a little performance increase because it already hits the first when clause instead of the second.
Patch is attached. All existing tests pass.