I would love to call a controller action from within a model. Yes, MVC. Thanks.
So, why would i like to call a controller action and fetch the response?
Because my controller knows how to render the file I would like to cache. Why should I duplicate code to collect all data needed by my view?
Setup:
- InvoicesController responds_to :html, :pdf
- Invoice uses state_machine (:new -> :open -> paid)
What I "need" within the state transition from :new to :open
- generate /invoices/:id.pdf
- cache the PDF as Invoice#file for later use in delayed_job or simliar
What interface i would love to use elsewhere?
@invoice.build_pdf
Any suggestions?
Update: I would like to cache the PDF as model attachement for later use (delayed_job mailing, etc)