Merge pull request #45110 from p8/guides/improve-routing-as-example

Improve prefixing routes example in guides [ci-skip]
This commit is contained in:
Petrik de Heus 2022-05-18 23:51:55 +02:00 committed by GitHub
commit 9cdb548da1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -1143,7 +1143,10 @@ end
resources :photos
```
This will provide route helpers such as `admin_photos_path`, `new_admin_photo_path`, etc.
This changes the route helpers for `/admin/photos` from `photos_path`,
`new_photos_path`, etc. to `admin_photos_path`, `new_admin_photo_path`,
etc. Without the addition of `as: 'admin_photos` on the scoped `resources
:photos`, the non-scoped `resources :photos` will not have any route helpers.
To prefix a group of route helpers, use `:as` with `scope`:
@ -1155,7 +1158,9 @@ end
resources :photos, :accounts
```
This will generate routes such as `admin_photos_path` and `admin_accounts_path` which map to `/admin/photos` and `/admin/accounts` respectively.
Just as before, this changes the `/admin` scoped resource helpers to
`admin_photos_path` and `admin_accounts_path`, and allows the non-scoped
resources to use `photos_path` and `accounts_path`.
NOTE: The `namespace` scope will automatically add `:as` as well as `:module` and `:path` prefixes.