ruby-on-railsruby-on-rails-4rails-enginesactionpackaction-caching

caches_action undefined for controller in rails engine


I've a Rails4 app a mounted rails 4 engine MyEngine with a controller MyController

I've defined multiple actions in the controller for caching as follows,

module MyEngine
   require 'actionpack/action_caching'
   class MyController < ApplicationController #inherits from application controller of app
       [:index, :show].each do |action|
           caches_action action
       end
   end
end

I've also included the gem actionpack-action_caching version 1.0.0 in my gemspec

spec.add_dependency "actionpack-action_caching", "1.0.0"

When I try to hit any route pointing to MyController I get following error:

ActionController::RoutingError - undefined method `caches_action' for MyEngine::MyController:Class:

I'm using development environment so I have also changed the configuration for the environment to enable caching:

config.action_controller.perform_caching = true

I've tried changing a bunch of things like adding this block to engine.rb in to_prepare and initializer block.

ActiveSupport.on_load :action_controller do
    require 'action_controller/action_caching'
end

I've also tried setting config.action_caching = true in engine.rb.

I'm sure I'm missing something very basic, just not able to find out what!

EDIT1

Tried adding caches_action for an action within the application as well. It throws the same error.

To debug I added some print statements inside the gem

On this line require 'action_controller/action_caching', and it prints true when the server starts up.

Thats more baffling!


Solution

  • I just upgraded to the latest 1.1.1 version of actionpack-action_caching, and it solved the issue.

    Thanks to Andrew White who responded to the issue I'd raised on Github.