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.

url_for should remember params[:format]

#3143

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.

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

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Jason Gignac
    Jason Gignac

    -1 Honestly, to me it makes more sense NOT to make the behaviour of url_for specific to the context in which it's executed. But, YMMV.

    May 8th, 2010 @ 01:37 PM

  2. Ryan Bigg
    Ryan Bigg

    This sees like a very narrow use-case, and I'd recommend that those who want this feature do it on their own project.

    May 25th, 2010 @ 11:44 AM

  3. Andrew Grimm
    Andrew Grimm

    This is a feature request that'd be used in a limited number of cases. Sorry.

    May 25th, 2010 @ 11:47 AM

  4. Ryan Bigg
    Ryan Bigg
    • State changed from new to wontfix

    May 25th, 2010 @ 12:07 PM