This project is archived and is in readonly mode.

#3143 ✓wontfix
Colin MacKenzie IV

url_for should remember params[:format]

Reported by Colin MacKenzie IV | September 4th, 2009 @ 03:50 AM

I'm using Rails 2.3.3.

I'm working with some custom formats (*.rtml.erb) which behave very similarly to HTML. I understand that my use case is, at best, a niche and that the standard way to use non-HTML formats is for XML, JSON, etc.

This may come down to semantics, but I expected Rails to "remember" my params[:format] value when I called url_for(:action => "some_other_action"). However, instead of ending up with /controller/action/id.rtml, I got the standard /controller/action/id.

For my own project, I've simply extended ActionController::Base#url_for to call super(options.reverse_merge(:format => params[:format])), which affected ActionView::Helpers::UrlHelpers#url_for due to its reliance on the former, but IMHO it makes more sense for Rails to do this on its own.

I'm familiar with XML, JSON, etc., but I'm not so familiar with the use cases under which these would reference other URLs. So, if this suggestion makes no sense, just say so. :) But from my own point of view, it would have been far more intuitive if Rails had picked up on my format automatically. As I see it (again, I may be naive in this respect), an .html file is more likely to reference another .html file, and an .xml file is more likely to reference another .xml file.

Comments and changes to this ticket

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=""></a>