开发者

How to access routes in Resque worker class?

I am running on Rails 3.1 RC5. Resque doesn't seem like it is ab开发者_StackOverflow社区le to access root_url from a worker class. I tried putting include Rails.application.routes.url_helpers to no avail.

For example:

module EncodePhoto
  include Rails.application.routes.url_helpers

  def self.perform()
    puts root_url
  end
end

Returns:

undefined method `root_url' for EncodePhoto:Module


If I am in a rails console, I can write:

include ActionController::UrlWriter

and then I can access the routes I need. Perhaps it can apply to your problem as well?

EDIT: Please see this. Here's the accepted answer from there:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜