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:

http://chienpo.blogspot.com/2011/06/where-am-i.html

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

https://gist.github.com/1015732

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" 
(http://guides.rubyonrails.org/routing.html#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.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/9wWKfOLyUHQJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to