Right now, I have a controller called Reports and inside of it I have a method called generate_pdf. When the user clicks the PDF icon, it routes to generate_pdf. Works fine.
However, now I am running a background task that needs to access the same code within generate_pdf from the Report controller.
How can I accomplish this? A redirect will not work because, again, it's a background process. Should I relocate this code elsewhere and just source it from there, or can I somehow just call the Report controller and past parameters? The end result of generate_pdf is rendering content to the user's web browser, but since this is a background task, I'm assuming it'll just return the content to whatever called it.
generate_pdfis referenced from theReportscontroller and from a background task, then perhaps a good place for it is inlib. Where is the background task defined? Your comment that you need the background task "to access the same code within generate_pdf from theReportcontroller." Is a little confusing. Do you mean the background task accesses theReportcontroller which, in turn, callsgenerate_pdf? IsReportdifferent thanReports? Ifgenerate_pdfis only referenced from multiple controllers, thenapp/controllers/concernswould be a good place for it.generate_pdfmethod within theReportscontroller. Sorry for the mixup between 'Reports' and 'Report' as well. it is just a single controller with a generate_pdf method that needs to be accessed by the user via the UI (just with a normal route that works properly) as well as a from sidekiq background worker.