I have a Rails app using load_and_authorize_resource to secure a controller.
I'm now trying to implement action caching on this controller but the action caching doesn't seem to work unless I comment out the load_and_authorize_resource directive. Has anyone else experienced this?
According to the CanCan documentation, the load_and_authorize_resource functionality works in a before filter so shouldn't conflict with caches_action.
I'm finding that when I exclude load_and_authorize_resource, the page is cached, and no database access is occurring after the first hit. However as soon as I re-introduce load_and_authorize_resource, the controller goes through all the logic for the action on every single request.
Any suggestions would be appreciated.
It's a before_filter that determines if a user has access to a particular action. Here's a link to rails documentation that might help.
But, I am not familiar with your code so I could be wrong. If this is still causing issues, please report back with some code and we'll open it again. Thanks.
Just in case somebody has the same issue, you probably had called the method check_authorization in your controller (or you parent controller). The caches_action caches the whole page and the before_filters are not executed. So cancan raises an exception because no authorization has been performed. If that is the case you could skip_authorization_check to bypass the verification.