如何在 resque 作业中使用 Rails 助手?
我正在尝试在我的 resque 工作中使用一些助手,但遇到了问题。这是我尝试过的:
require 'json'
class SoulmateUserFollowing
tried this -> include Rails.application.routes.url_helpers
and this -> include ActionView::Helpers:UrlHelper
and this -> helper ActionView::Helpers::UrlHelper
@queue = :soulmate_user
def self.perform(user_id)
user = User.find(user_id)
url = url_for(following_user)
end
end
我还需要包含带有 image_path 方法的帮助程序和位于模块 ImageHelper 中的自定义帮助程序。
I'm trying to use some helpers in my resque job and am running into problems. Here's what I've tried:
require 'json'
class SoulmateUserFollowing
tried this -> include Rails.application.routes.url_helpers
and this -> include ActionView::Helpers:UrlHelper
and this -> helper ActionView::Helpers::UrlHelper
@queue = :soulmate_user
def self.perform(user_id)
user = User.find(user_id)
url = url_for(following_user)
end
end
I also need to include the helper with the image_path method and a custom helper of mine located in module ImageHelper.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 config/routes.rb 文件中添加命名路由,然后从作业类中调用它(无需包含任何内容)
您还必须在环境中设置默认主机,因为您位于“resque”内并且没有 http参数设置。
或者,您可以包含 url_helpers 并在您的班级中执行类似的操作
Add a named route in your config/routes.rb file and then call it from your job class (no need to include anything)
You also have to set in your environment the default host since you are inside 'resque' and there are no http parameters set.
Alternatively you can include the url_helpers and do something like this in your class