This project is archived and is in readonly mode.
link_to duplicates behavior of url_for
Reported by Clemens Kofler | July 19th, 2008 @ 12:12 AM | in 2.x
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.
Comments and changes to this ticket
-
josh July 19th, 2008 @ 09:26 PM
- State changed from new to resolved
- Assigned user set to josh
Didn't see the ticket. I already pulled from your github repo.
If lighthouse will let you, assign all your AV form helper patches to me.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>