Skip to content

undefined method caches_action for Controller, with Rails 4 #12

@praveenram

Description

@praveenram

I'm using Rails 4.0.0 stable with actionpack-action_caching 1.0.0, a very weird issue when using a rails engine.

I'm pasting the question I'd posted on StackOverflow here.

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!

Link to question: caches_action undefined for controller in rails engine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions