v2.1.0 - Show latest stable - 2 notes

Write URLs from arbitrary places in your codebase, such as your mailers.

Example:

  class MyMailer
    include ActionController::UrlWriter
    default_url_options[:host] = 'www.basecamphq.com'

    def signup_url(token)
      url_for(:controller => 'signup', action => 'index', :token => token)
    end
 end

In addition to providing url_for, named routes are also accessible after including UrlWriter.

Show files where this module is defined (1 file)
Register or log in to add new notes.
January 6, 2011 - (>= v3.0.0)
2 thanks

Accessing URL helpers in Rails 3

I’ve been upgradings an app to Rails 3 and it took me a bit to find this-

If you were using

include ActionController::UrlWriter

to get the url helpers in rails 2, you should switch to

include Rails.application.routes.url_helpers

for Rails 3

From: http://snipplr.com/view/37063/to-access-url-helpers-urlfor-etc-from-rails-console-rails-3/