Skip to content

Commit d86bf21

Browse files
excid3skipkayhil
authored andcommitted
Clarify unsubscribe route
This adds some context around where the route goes and why it's a singular route to address questions that have come up recently. Co-authored-by: Hartley McGuire <[email protected]>
1 parent 03998c3 commit d86bf21

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

guides/source/getting_started.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,10 +2363,17 @@ A subscriber may want to unsubscribe at some point, so let's build that next.
23632363
First, we need a route for unsubscribing that will be the URL we include in
23642364
emails.
23652365

2366-
```ruby
2366+
```ruby#6
2367+
Rails.application.routes.draw do
2368+
# ...
2369+
resources :products do
2370+
resources :subscribers, only: [ :create ]
2371+
end
23672372
resource :unsubscribe, only: [ :show ]
23682373
```
23692374

2375+
The unsubscribe route is added at the top level and uses the singular `resource` in order to handle routes like `/unsubscribe?token=xyz`.
2376+
23702377
Active Record has a feature called `generates_token_for` that can generate
23712378
unique tokens to find database records for different purposes. We can use this
23722379
for generating a unique unsubscribe token to use in the email's unsubscribe URL.

0 commit comments

Comments
 (0)