Do self-referencing link/URL helpers like these exist already?

Hello everyone.

Okay, I’ve done a full write-up of my question here as a blog post. It includes a TL;DR section at the top:

The code containing the “helpers” I referred to in the title of this question is here:

For those who don’t want to visit the linked pages:

I’ve written 3 view helpers, #link_to_self, #url_for_self, and #path_for_self. As you may have guessed, they’re very similar to the standard #url_for and #link_to helpers but with the url/link destination hard-coded (for certain values of “hard-coded”) to refer to the same exact url as the current request.

They’re really very simple and basically use the request.fullpath (and request.query_parameters). The reason I don’t just use #url_for (or #link_to) to generate self-referencing URLs (by not providing any :controller, :action, etc.) is more fully described in the links above but briefly:

  1. For resources that can be accessed via multiple routes, using #url_for for self-referencing will always choose the first route that appears in config/routes.rb. I want a method that always returns the path actually used to access the current resource.

  2. I wanted an easy-to-use, self-referencing URL generator that, by default, includes all the query string parameters (and only query string ones, no POST params) that were passed as part of the current request. Included is the ability to add (merge) in new params, mark some for removal, and overwrite existing values individually.

  3. This is far more of a corner case than the above two: I want my helper(s) to allow me to provide any key value in my hash for construction of my query string and not have it extracted and interpreted by the router. In other words, any of the special “bound parameters” ( like :action, :controller, :id, whatever else you define in your custom routes, can still be passed to these helpers. The value won’t be consumed (to create a non-self-referencing URL) and will be added to the query string.

My “question”, in addition to the one in the subject/title of this email/post, is: would these be useful enough to a broad enough audience to ever be considered as potential additions to rails? I’d also just like any feedback from anyone with regards to the code/implementation, etc.