Skip to content

Instantly share code, notes, and snippets.

@dust3d
Forked from mindscratch/routes.rb
Created August 24, 2011 02:42
Show Gist options
  • Save dust3d/1167181 to your computer and use it in GitHub Desktop.
Save dust3d/1167181 to your computer and use it in GitHub Desktop.
Rails (3.0.x): easily namespace routes for entire app
MyApp::Application.routes.draw do
my_draw = Proc.new do
#get "widgets" => "widgets#index"
# add routes here
end
# I chose to name my environment variable 'RAILS_RELATIVE_URL_ROOT' but it can
# be anything you want.
#
# In production I was deploying my Rails app (as a WAR, thanks to the warbler gem) to a Tomcat server.
# Tomcat associates applications to the name of the directory that gets created when a WAR file is
# is exploded, so if my WAR was named 'myapp.war' then I would end up with /path/to/tomcat/webapps/myapp
# which could be accessed via a browser at http://<server name>:<port>/myapp
#
# In development I wanted to test my app in a similar scenario but WEBrick (or whatever you use)
# doesn't work that way. So, I'd set the env. variable to '/myapp' and then when I ran my Rails app
# using "rails s"..I could access it as http://localhost:3000/myapp
if Rails.env != 'production'
puts "drawing routes inside scope: /vault"
scope '/vault' do
my_draw.call
end
else
my_draw.call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment