Skip to content

Instantly share code, notes, and snippets.

@mattyoho
Created July 8, 2009 03:33
Show Gist options
  • Save mattyoho/142560 to your computer and use it in GitHub Desktop.
Save mattyoho/142560 to your computer and use it in GitHub Desktop.
Access Rails routes from outside of controllers/views. Most rules have exceptions, folks.
class CanHazRoutes
include ActionController::UrlWriter
host = case ENV['RAILS_ENV']
when "production"
"prod.com"
when "staging"
"stage.com"
when "development"
"app.local"
end
default_url_options[:host] = host
def url_kthx(m)
polymorphic_url_for(m)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment