We have a Rails app that has some pages that are available to all and pages you only see when you are logged. We call them ‘public’ pages and ‘application’ pages. Since the public pages don’t changes, we want to enable page caching for them. One solution for that would be to manually add
caches_page :index, ..
to all our public controllers. However, I don’t find this convenient and Rubyish. All our public controllers inherit from a PublicController class (some shared methods, behavior, ..), so I thought of putting the caching method also in the PublicController so that all public controllers are cached by default (again, public means more or less static content). However there exists no
caches_page :all
in Rails. I thought of using something like
self.new.public_methods(false)
and then iterate through them and add them to caching. But since this is in the PublicController, no actual actions are listed.
Does anyone have a good solution for this problem? Or is the manual way the only way to go.
Thank you!
From looking at the way that
caches_pageworks it looks like you can add a filter to do it: