我们有一个帮助方法,用于在视图和通过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
答案 0 :(得分:4)
这对我有用
ApplicationController.helpers.accept_url(cleaner, occurrence)