【发布时间】:2016-07-14 15:28:44
【问题描述】:
我在 Rails 4 上使用带有 Redis 的 Resque。
我的问题:如何在后台作业中使用当前在 application_controller 中定义的控制器方法?
这是我定义的当前方法:
def push_to_google(token, message)
if token.present?
gcm = GCM.new("843jf9384fj839f848j890fj3")
registration_ids = ["#{token}"] # an array of one or more client registration tokens
options = {data: {notification: "#{message}"}}
response = gcm.send(registration_ids, options)
end
end
我想在 delay_notifications 中定义的后台作业中使用它:
class DelayedNotifications
@queue = :notifications_queue
def self.perform(registration_id, user_name)
push_to_google(registration_id, "New message from #{user_name}.")
end
end
当然,我的工作目前因此错误而失败:
undefined method 'push_to_google' for DelayedNotifications:Class
提前感谢您的帮助。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 controller redis resque