Skip to content

Commit

Permalink
Ensure _prefixes is not available as an action method on controllers
Browse files Browse the repository at this point in the history
There was a change introduced in Rails 7.1 that causes all public
actions of non-abstract controllers to become action methods, even if
they happen to match the name of an internal method defined by abstract
`ActionController::Base` and such, which is the case with `_prefixes`.

This change was intentional, it allows for example to have an action
called `status`, which is an internal method, and that is properly
managed as an action method now. However, it broke Devise due to
overriding `_prefixes`, which is a public method of Action Controller.

To fix, we are simply ensuring we keep `_prefixes` as an internal method
rather than action method, which matches previous behavior for this
particular method/implementation in Devise.

Ref: rails/rails#48699
  • Loading branch information
carlosantoniodasilva committed Oct 10, 2023
1 parent 218d14a commit f2a42ab
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/devise_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def _prefixes #:nodoc:
end
end

# Override internal methods to exclude `_prefixes` since we override it above.
# There was an intentional change in Rails 7.1 that will allow it to become
# an action method because it's a public method of a non-abstract controller,
# but we also can't make this abstract because it can affect potential actions
# defined in the parent controller, so instead we ensure `_prefixes` is going
# to be considered internal. (and thus, won't become an action method.)
# Ref: https://github.com/rails/rails/pull/48699
def self.internal_methods #:nodoc:
super << :_prefixes
end

protected

# Gets the actual resource stored in the instance variable
Expand Down

0 comments on commit f2a42ab

Please sign in to comment.