Skip to content

Commit

Permalink
Adjust README for switching users to use Rails 8
Browse files Browse the repository at this point in the history
I'm not sure about the `should_switch_user?` pattern we're implicitly suggesting here.

I rewrote the code sample to use the Rails 8 generators. I think this is roughly what it should look like for real.
  • Loading branch information
Burgestrand committed Nov 22, 2024
1 parent c0e2d0e commit bfa0de5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,11 @@ To handle user switching, you can use the following pattern in your controller:
```ruby
class ApplicationController
include Pundit::Authorization
before_action :switch_user, if: :should_switch_user?

def switch_user
current_user = User.find(params[:user_id])
pundit_reset! # Ensure that the Pundit context is reset for the new user
def switch_user_to(user)
terminate_session if authenticated?
start_new_session_for user
pundit_reset!
end
end
```
Expand Down

0 comments on commit bfa0de5

Please sign in to comment.