This project is archived and is in readonly mode.
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
-
Jason Gignac May 8th, 2010 @ 01:37 PM
-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.
-
Ryan Bigg May 25th, 2010 @ 11:44 AM
This sees like a very narrow use-case, and I'd recommend that those who want this feature do it on their own project.
-
Andrew Grimm May 25th, 2010 @ 11:47 AM
This is a feature request that'd be used in a limited number of cases. Sorry.
-
Ryan Bigg May 25th, 2010 @ 12:07 PM
- State changed from new to wontfix
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>