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

Update README to include note on reloading guest_user #49

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ guest_user # ( for anonymous users)

### Transferring Guest to User on Login

During the login process you may want to transfer things from your guest user to the account the logged into.
During the login process you may want to transfer things from your guest user to the account they logged into.
To do so, add the following method to your ApplicationController:

```ruby
Expand All @@ -58,6 +58,13 @@ def transfer_guest_to_user
else
guest_user.cart.update!(user: current_user)
end

# In this example we've moved `LineItem` records from the guest
# user's cart to the logged-in user's cart.
#
# To prevent these being deleted when the guest user & cart are
# destroyed, we need to reload the guest record:
guest_user.reload
end
```

Expand Down
Loading