Search code examples
ruby-on-railsresqueurlhelper

Use Rails path helpers from inside an plain old ruby class? (Resque job)


I need to make some API calls from inside a Resque job (which is just a plain old Ruby class) and those API calls need to include URLs to resources on my site.

Is it "correct" to just add this to my class definition?

include Rails.application.routes.url_helpers

Or is there an "expected" way to do this?


Solution

  • It seems that is the way to do it.

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

    linked to from here http://apidock.com/rails/ActionController/UrlWriter