-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken in Rails 7 #79
Comments
@sasharevzin I am not able to reproduce this. Can your share some repro? |
Hi @fatkodima, Here the repo. PS. Issue with |
I made some investigation. From the repro app: class HomeController < ApplicationController
include ActionController::Caching
caches_action :index
def index
render json: { time: Time.current }
end
end The problem is that you included After the source code was parsed, it is executed as the following:
So, the proposed solution (without changing rails'): diff --git a/lib/action_controller/action_caching.rb b/lib/action_controller/action_caching.rb
index aee19c1..5a2a243 100644
--- a/lib/action_controller/action_caching.rb
+++ b/lib/action_controller/action_caching.rb
@@ -13,3 +13,12 @@ module ActionController
end
ActionController::Base.send(:include, ActionController::Caching::Actions)
+
+unless ActionController::API.include?(ActionController::Caching)
+ ActionController::API.class_eval do
+ include ActionController::Caching
+
+ self.perform_caching = ActionController::Base.perform_caching
+ self.cache_store = ActionController::Base.cache_store
+ end
+end
diff --git a/lib/action_controller/caching/actions.rb b/lib/action_controller/caching/actions.rb
index a45c801..4e05556 100644
--- a/lib/action_controller/caching/actions.rb
+++ b/lib/action_controller/caching/actions.rb
@@ -159,9 +159,9 @@ module ActionController
body = controller.read_fragment(cache_path.path, @store_options)
unless body
- controller.action_has_layout = false unless cache_layout
+ controller.action_has_layout = false if !cache_layout && controller.respond_to?(:action_has_layout=)
yield
- controller.action_has_layout = true
+ controller.action_has_layout = true if controller.respond_to?(:action_has_layout=)
body = controller._save_fragment(cache_path.path, @store_options)
end Or we can include @rafaelfranca Can you give some input on this? |
I think for the first part of the diff (including The second part of the diff is correct, but maybe we should only check if the method exists once and if not we just yield and set the body. |
Thank you, @fatkodima. PR looks good to me (can't merge not the owner) 😢 |
It looks like some of methods no longer exist in Rails 7
The text was updated successfully, but these errors were encountered: