Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (26 sloc) 1.12 KB


sinatra-url-for constructs absolute paths and full URLs for handlers in a Sinatra application. Assuming that your application is running on, and that it has been mapped to /myapp, you should be able call url_for from within a handler as follows:

url_for "/"            # Returns "/myapp/"
url_for "/foo"         # Returns "/myapp/foo"
url_for "/foo", :full  # Returns ""

To install it, run:

sudo gem install emk-sinatra-url-for -s

To include it in a Sinatra application, write:

require 'rubygems'
gem 'emk-sinatra-url-for'
require 'sinatra/url_for'

If you're subclassing Sinatra::Base, then you need to call helpers manually:

class MyApp < Sinatra::Base
  helpers Sinatra::UrlForHelper
  # ...

Thanks to “cypher23” on #mephisto and the folks on #rack for pointing me in the right direction. If this gem fails to work correctly on your system, please feel free to submit patches and/or bug reports!


Copyright 2009 Eric Kidd. See LICENSE for details.

Jump to Line
Something went wrong with that request. Please try again.