Uninitialized content when trying to include ActionController :: UrlWriter in the model

I am using Rails 3 beta 4 and trying to include ActionController :: UrlWriter in my model, this is the right way to do this, as far as I can tell, but I get "Uninitialized Constant ActionController :: UrlWriter",

Any idea why this would be? Did he move on rails 3?

+3
source share
2 answers

At first I agree with zed. This should not be done in the model. Your models do not need to know about the http address.

I do the same in resque work. That's what I'm doing:

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

Then you can call any regular url generator.

url_for(object)
page_url(object)

It will create a link on the node defined as default_url_options[:host]

+3
source

Source: https://habr.com/ru/post/1749340/


All Articles