Routing conventions
Rails has a nice section on naming routes and actions.
Route | File | Used to show |
---|---|---|
/photos |
index | List of photos |
/photos/new |
new | Form for creating new photo |
/photos/:id |
show | Show photo |
/photos/:id/edit |
edit | Form for editing photo |
/photos/:id/delete |
delete | Form for deleting photo |
But this doesn’t cover multi-step flows, so I’ll note here the way I do it.
(Note: I’ll focus on the GETs becuase all the POSTs should be to the same url with a redirect.)
Creating a profile #
So let’s say you need to create your profile which is made up of your name and email address just to keep things simple enough to demonstrate.
Route | File path | Used to show |
---|---|---|
/profile/new |
profile/new/name | Form asking for first and last name |
/profile/new/email-address |
profile/new/email-address | Form asking for email address |
/profile/new/check-answers |
profile/new/check-answers | Check answers page |
/profile/new/confirmation |
profile/new/confirmation | Confirmation page |
I still use /new
to point to the first screen of the flow. But then I’ll sub directories to identify the additional steps.
Edit your email address #
Now, let’s say you want to edit your email address which is part of your profile.
Route | File path | Used to show |
---|---|---|
/profile/edit-email |
profile/edit-email/current-email-address | Form asking for current address |
/profile/edit-email/new-email-address |
profile/edit-email/new-email-address | Form asking for new address |
/profile/edit-email/check-answers |
profile/edit-email/check-answers | Check answers page |
/profile/edit-email/confirmation |
profile/edit-email/confirmation | Confirmation page |
Instead of /edit
I’m using /edit-email
to be specific about what part of the profile is being edited.
And again the first screen is just the intended action with sub directories for the additional steps.
(Note: if you were editing an item in a collection, just whack the id in the URL. Something like /photos/:id/edit-photo
.)
Get my design tips in your inbox
Join 4000 subscribers who get my design tips about relentlessly simple and accessible patterns that are easy to use.