1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improve prefixing routes example in guides [ci-skip]

The current example is ambiguous as it uses 'admin' for both the scope
and `:as` option.
This change clarifies the example by explaining what `scope` does and
what the `:as` option does.

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
This commit is contained in:
Petrik 2022-05-18 22:42:03 +02:00
parent a680a684d1
commit b9d3108420

View file

@ -1143,7 +1143,10 @@ end
resources :photos 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`: To prefix a group of route helpers, use `:as` with `scope`:
@ -1155,7 +1158,9 @@ end
resources :photos, :accounts 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. NOTE: The `namespace` scope will automatically add `:as` as well as `:module` and `:path` prefixes.