[PLUGIN] url_for_with_prefix - allowing you to modify/remove

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

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
link_to “My Other App”, :controller => “other_app_controller”,
:prefix => “/amazing” # =>
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

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.

Plugin is available at
http://svn.flpr.org/public/plugins/url_for_with_prefix

Pat:

Very nice.

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

See Fixme 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!!!

Posted at http://agilewebdevelopment.com/plugins/urlforwithprefix :slight_smile:


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