Construct absolute paths and full URLs to actions in a Sinatra application
Failed to load latest commit information.
lib/sinatra URI.escape is sensitive about being given strings to escape Mar 6, 2011
spec Test for, and explicitly support, two-form call with existing options… Mar 6, 2011
.document Initial commit to sinatra-url-for. Apr 22, 2009
.gitignore Fix gemspec and add bundler support Mar 6, 2011
LICENSE Initial implementation for url_for Apr 22, 2009
README.rdoc README: Edit for clarity Apr 22, 2009
Rakefile Rakefile: Add dependencies Apr 22, 2009
VERSION.yml Version bump to 0.2.1 Apr 22, 2009



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.