views:

190

answers:

1

I'm using Rails 3 beta 4 and trying to include ActionController::UrlWriter in my model, which is the correct way to go about it as far as i can tell, but i get "Uninitialized Constant ActionController::UrlWriter".

Any idea why that would be? Did it move in rails 3?

A: 

First I agree with zed. This shouldn't be done in a model. Your models should be unaware of any http url.

I do the same in a resque job. Here's what I do :

include ActionDispatch::Routing::UrlFor
include ActionController::PolymorphicRoutes
include Rails.application.routes.url_helpers
default_url_options[:host] = 'example.com'

Then you can call any usual url generator.

url_for(object)
page_url(object)

It'll create the link on the host defined as default_url_options[:host]

Damien MATHIEU