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
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
For resources that can be accessed via multiple routes, using
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
to access the current resource.
I wanted an easy-to-use, self-referencing URL generator that, by
includes all the query string parameters (and only query string ones, no
POST params) that were passed as part of the current request. Included
the ability to add (merge) in new params, mark some for removal, and
overwrite existing values individually.
This is far more of a corner case than the above two: I want my
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.
other words, any of the special “bound parameters”
:controller, :id, whatever else you define in your custom routes, can
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
ever be considered as potential additions to rails? I’d also just like
feedback from anyone with regards to the code/implementation, etc.