0.0
No commit activity in last 3 years
No release in over 3 years
Construct absolute paths and full URLs for a Sinatra application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.1.11

Runtime

>= 0.9.1.1
 Project Readme

sinatra-url-for¶ ↑

sinatra-url-for constructs absolute paths and full URLs for handlers in a Sinatra application. Assuming that your application is running on example.com, 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 "http://example.com/myapp/foo"

To install it, run:

sudo gem install emk-sinatra-url-for -s http://gems.github.com

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
  # ...
end

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.