Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I selectively turn off template caching in Rails?

I am sending emails in a background job using ActionMailer. Users can create new email templates but they aren't recognized until the background job is restarted. Used to use

ActionView::TemplateFinder.reload!

which forced reloading of templates (now deprecated on 2.3.4). I have tried

ActionView::Base.cache_template_loading = false

but that does not work.

like image 687
SteveD Avatar asked Nov 20 '25 06:11

SteveD


1 Answers

What I wound up doing was setting a global variable in my background process before the Rails environment was loaded:

$background = true

then in environments/production.rb:

config.action_view.cache_template_loading = !$background

Not thrilled, but it works. I get template reloading for email templates in my background job but cached view templates for the online application.

like image 110
SteveD Avatar answered Nov 21 '25 20:11

SteveD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!