Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

link_to duplicates behavior of url_for

#657

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.

Reported by Clemens Kofler · July 19th, 2008 @ 12:12 AM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • 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.

    July 19th, 2008 @ 09:26 PM