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

**URL:** <https://www.ruby-forum.com/t/do-self-referencing-link-url-helpers-like-these-exist-already/208138>\
**Category:** Rails\
**Created:** [June 11, 2011, 12:03am UTC](https://www.ruby-forum.com/t/do-self-referencing-link-url-helpers-like-these-exist-already/208138 "2011-06-11T00:03:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 11, 2011, 12:03am UTC](https://www.ruby-forum.com/t/do-self-referencing-link-url-helpers-like-these-exist-already/208138/1 "2011-06-11T00:03:43Z")

</div>

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:

> **[Where am I?](http://chienpo.blogspot.com/2011/06/where-am-i.html)**
>
> A blog about programming, ruby, rails, and IT stuff. My (Kendall Gifford) nickname is Chien Po (chienpo) and I post personal ramblings here too.

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

[https://gist.github.com/1015732](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”  
([Rails Routing from the Outside In — Ruby on Rails Guides](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!
