ActionController::UrlRewriter's url_for and link_to

Hi,

I'm upgrading an app to 2.3 and can't figure out how to resolve this issue:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1560

In earlier versions (I'm coming from 2.1) link_to did this:

url = case options   when String     options   when :back     @controller.request.env["HTTP_REFERER"] || 'javascript:history.back ()'   else     self.url_for(options)   end

whereas now it just does a unconditional

url = url_for(options)

If you include

ActionController::UrlWriter

somewhere and do a link_to with a named route you get the nice "TypeError: can't convert String into Hash" exception, because url_for in UrlWriter doesn't know how to handle Strings.

Would love to work on a patch, but I have no idea how this is supposed to work:

    * just change the link_to implementation?     * change UrlWriter#url_for to handle Strings as options?     * am I doing something wrong?

thanks, Florian

There are, I believe, three separate implementations of #url_for: one in ActionController::Base, one in ActionController::UrlWriter, and one in ActionView::Helpers::UrlHelper. I've looked for the exact incantation for when, and in what order, to include each of these without success; also, they communicate to one another through instance variable, which you have to have set up correctly.

Where exactly are you running into these problems? As unsatisfying as this answer will be for you, I generally solve these types of problems by only creating URLs in Rails-sanctioned objects (controllers and views). It's possible to get the behavior working in other objects, but it will make your head hurt.