Skip to content
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

Rails 5 support for ActionController::Base and ActionController::API #484

Closed
arturoherrero opened this issue Feb 20, 2018 · 2 comments · Fixed by #491
Closed

Rails 5 support for ActionController::Base and ActionController::API #484

arturoherrero opened this issue Feb 20, 2018 · 2 comments · Fixed by #491
Assignees
Labels

Comments

@arturoherrero
Copy link
Contributor

Hello there!

I'm trying to update from version 2.1.0 to 2.1.3 but I'm having problems regarding #457.

I have one Rails app using both kinds of controllers:

  • ActionController::Base Standard Application
  • ActionController::API API-only Applications

These are the changes from @Eric-Guo:

diff --git a/lib/cancan/controller_additions.rb b/lib/cancan/controller_additions.rb
index 7c3c74a..7949d2e 100644
--- a/lib/cancan/controller_additions.rb
+++ b/lib/cancan/controller_additions.rb
@@ -384,9 +384,12 @@ module CanCan
   end
 end

-if defined? ActionController
-  %w[Base API].each do |klass|
-    next unless ActionController.const_defined?(klass)
-    ActionController.const_get(klass).class_eval { include CanCan::ControllerAdditions }
+if defined? ActionController::Base
+  ActionController::Base.class_eval do
+    include CanCan::ControllerAdditions
+  end
+elsif defined? ActionController::API
+  ActionController::API.class_eval do
+    include CanCan::ControllerAdditions
   end
 end

I think we should apply include CanCan::ControllerAdditions to both ActionController::Base and ActionController::API as CanCanCan was doing before; otherwise, applications using both controllers have to manually include ControllerAdditions in the ActionController::API classes.

@arturoherrero
Copy link
Contributor Author

What is the problem with the following code?

if defined? ActionController::Base
  ActionController::Base.class_eval do
    include CanCan::ControllerAdditions
  end
end

if defined? ActionController::API
  ActionController::API.class_eval do
    include CanCan::ControllerAdditions
  end
end

@coorasse
Copy link
Member

Completely agree. Please open a PR for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants