From b9d31084206f7243d813e4555cea0598721b850b Mon Sep 17 00:00:00 2001 From: Petrik Date: Wed, 18 May 2022 22:42:03 +0200 Subject: [PATCH] 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 --- guides/source/routing.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/guides/source/routing.md b/guides/source/routing.md index e1e92358fb..f4d32048d0 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -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.