# \[PLUGIN\] url\_for\_with\_prefix - allowing you to modify/remove

**URL:** <https://www.ruby-forum.com/t/plugin-url-for-with-prefix-allowing-you-to-modify-remove/95997>\
**Category:** Rails\
**Created:** [June 22, 2006, 2:08am UTC](https://www.ruby-forum.com/t/plugin-url-for-with-prefix-allowing-you-to-modify-remove/95997 "2006-06-22T02:08:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [June 22, 2006, 2:08am UTC](https://www.ruby-forum.com/t/plugin-url-for-with-prefix-allowing-you-to-modify-remove/95997/1 "2006-06-22T02:08:39Z")

</div>

Here’s the readme. I think it’s okay to post this kind of thing to  
the mailing list. Anyway, hopefully someone else finds this useful.

# UrlForWithPrefix

By Pat M.

Very simple plugin, adds the :prefix option to url\_for.

Say in your environment.rb file you’ve got  
ActionController::AbstractRequest.relative\_url\_root = “/super”

Any time you use link\_to, it will prepend /super to the link. This  
can be a pain if you want to link to other applications:  
link\_to “My Other App”, :controller =\> “other\_app\_controller” # =\>  
“[http://mysite/super/other\_app\_controller](http://mysite/super/other_app_controller)”

You’d like to be able to set a different prefix, or take it out  
altogether. With this plugin, you can do that:  
link\_to “My Other App”, :controller =\> “other\_app\_controller”,  
:prefix =\> nil # =\> “[http://mysite/other\_app\_controller](http://mysite/other_app_controller)”  
link\_to “My Other App”, :controller =\> “other\_app\_controller”,  
:prefix =\> “/amazing” # =\>  
“[http://mysite/amazing/other\_app\_controller](http://mysite/amazing/other_app_controller)”

Keep in mind when setting a new prefix, you must have a beginning /,  
otherwise it will keep the original prefix AND use the new prefix:  
link\_to “My Other App”, :controller =\> “other\_app\_controller”,  
:prefix =\> “amazing” # =\>  
“[http://mysite/super/amazing/other\_app\_controller](http://mysite/super/amazing/other_app_controller)”

Wish I could say I had awesome unit tests, but I don’t. This has  
worked in all of my apps so far, but I can’t guarantee that it won’t  
break something, or that a future Rails update won’t break this  
plugin.

I don’t really understand licenses, so do whatever you want with this,  
I’d just appreciate a link back to [www.flpr.org](http://www.flpr.org).

Plugin is available at  
[http://svn.flpr.org/public/plugins/url\_for\_with\_prefix](http://svn.flpr.org/public/plugins/url_for_with_prefix)

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [June 22, 2006, 3:52am UTC](https://www.ruby-forum.com/t/plugin-url-for-with-prefix-allowing-you-to-modify-remove/95997/2 "2006-06-22T03:52:51Z")

</div>

Pat:

Very nice.

Just FYI… I released a simliar plugin to this back in May.

See [Fixme](http://www.napcsweb.com/rdoc/reverse_proxy_fix/index.html) for info  
on  
this

Mine is meant to be a site-wide approach for forcing users to come back  
through a proxy. Yours looks great for making it really easy to  
integrate  
multiple applications with ease. Good work!!!

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [June 22, 2006, 4:45am UTC](https://www.ruby-forum.com/t/plugin-url-for-with-prefix-allowing-you-to-modify-remove/95997/3 "2006-06-22T04:45:55Z")

</div>

Posted at [http://agilewebdevelopment.com/plugins/urlforwithprefix](http://agilewebdevelopment.com/plugins/urlforwithprefix) 🙂

–  
Benjamin C.  
[http://www.bencurtis.com/](http://www.bencurtis.com/)  
[http://www.tesly.com/](http://www.tesly.com/) – Collaborative test case management  
[http://www.agilewebdevelopment.com/](http://www.agilewebdevelopment.com/) – Resources for the Rails community
