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/…


This content originally appeared on Adam Silver and was authored by Adam Silver

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.)


This content originally appeared on Adam Silver and was authored by Adam Silver


Print Share Comment Cite Upload Translate Updates
APA

Adam Silver | Sciencx (2020-04-18T00:00:00+00:00) Routing conventions. Retrieved from https://www.scien.cx/2020/04/18/routing-conventions/

MLA
" » Routing conventions." Adam Silver | Sciencx - Saturday April 18, 2020, https://www.scien.cx/2020/04/18/routing-conventions/
HARVARD
Adam Silver | Sciencx Saturday April 18, 2020 » Routing conventions., viewed ,<https://www.scien.cx/2020/04/18/routing-conventions/>
VANCOUVER
Adam Silver | Sciencx - » Routing conventions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/04/18/routing-conventions/
CHICAGO
" » Routing conventions." Adam Silver | Sciencx - Accessed . https://www.scien.cx/2020/04/18/routing-conventions/
IEEE
" » Routing conventions." Adam Silver | Sciencx [Online]. Available: https://www.scien.cx/2020/04/18/routing-conventions/. [Accessed: ]
rf:citation
» Routing conventions | Adam Silver | Sciencx | https://www.scien.cx/2020/04/18/routing-conventions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.