Skip to content

Instantly share code, notes, and snippets.

@lsemel
Created September 29, 2010 06:46
Show Gist options
  • Save lsemel/602380 to your computer and use it in GitHub Desktop.
Save lsemel/602380 to your computer and use it in GitHub Desktop.
# This class gives you all the Rails 3 URL helpers, which are so
# unhelpfully unavailable in models, libraries, and unit tests
# Stick this in the library folder and get a URL with
# UrlHelpers.new.nameofmodel_url
class UrlHelpers
include Rails.application.routes.url_helpers
def initialize
default_url_options[:host] = case Rails.env
when "development" then "localhost"
when "production" then "yourdomain.com"
when "test" then "localhost"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment