在ActiveJob中使用自定义Rails帮助程序

时间:2015-10-29 07:27:41

标签: ruby-on-rails ruby-on-rails-4 rails-activejob

我们有一个帮助方法,用于在视图和通过ActiveJob发送的SMS中生成URL。

我们如何在作业中访问辅助方法?

module Crew::AvailableJobsHelper
  def accept_url(cleaner, occurrence)
    if some_condition_is_true
      crew_accept_job_url(cleaner_id: cleaner.id, job_id: occurrence.job.id)        
    else
      crew_accept_occurrence_url(cleaner_id: current_user.id, occurrence_id: occurrence.id)
    end
  end
end

class Crew::UnassignedAlertJob < ActiveJob::Base
  queue_as :default

  def perform
    sms_body = "Click here to accept a job: #{accept_url(cleaner, occurrence)}"
  end
end

1 个答案:

答案 0 :(得分:4)

这对我有用

ApplicationController.helpers.accept_url(cleaner, occurrence)