开发者

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

开发者 https://www.devze.com 2023-04-07 22:56 出处:网络
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.

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?


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


In your controller:

Rails 1.x: include Rails.application.routes.url_helpers

Rails 2.x: include ActionController::UrlWriter

0

精彩评论

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