1
我們有一個幫助器方法,我們用它來在視圖中和通過ActiveJob發送的SMS中生成URL。在ActiveJob中使用自定義Rails幫助器
我們如何在作業中訪問幫助器方法?
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
試試這個#{ApplicationController.helpers.accept_url(清潔劑,發生)} –