Skip to content

Commit

Permalink
Clarify an example that does not work as it is [ci-skip]
Browse files Browse the repository at this point in the history
This snippet was hard to decipher and I'd like to propose that it be clarified.

`'_your_app_session'` as the default name of the cookie is a common placeholder
throughout the guides which we can use for consistency.

With these changes we are less likely to cause an immediate trouble,
which is the NoMethodError as a result of `cookie.encrypted['_session']` being nil.
  • Loading branch information
sato11 committed Feb 6, 2024
1 parent 6b2a9f1 commit 6e33c8e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions guides/source/action_cable_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,10 @@ by this same current user, you're also ensuring that you can later retrieve all
connections by a given user (and potentially disconnect them all if the user is deleted
or unauthorized).

If your authentication approach includes using a session, you use cookie store for the
session, your session cookie is named `_session` and the user ID key is `user_id` you
can use this approach:
If your authentication approach includes using a session, you can use this approach:

```ruby
verified_user = User.find_by(id: cookies.encrypted['_session']['user_id'])
verified_user = User.find_by(id: cookies.encrypted['_your_app_session']['user_id'])
```

[`ActionCable::Connection::Base`]: https://api.rubyonrails.org/classes/ActionCable/Connection/Base.html
Expand Down

0 comments on commit 6e33c8e

Please sign in to comment.