Member-only story

Rails Routes P.1 Understanding Route Structure

Steven Klavins
2 min readMar 14, 2021

--

One of the most confusing things I found whilst learning Rails was how to correctly use routes. It is my hope through this blog I can uncover some of the magic our routes.rb facilitates.

To list the existing routes in your project simply run

rails routes

When running this command your terminal will provide output similar to the screenshot below. You can refine your search to specific model names using a pipe, for example..

rails routes | grep blog

This will refine our search to only show routes linked with the blog model, this is particularly useful when working with larger applications.

Note: depending on your version of Rails and configuration these collum’s may be ordered differently, however they will contain the information that follows.

Ok so let's cover what these routes actually do!

Collum one (left)

On the left we see a model followed by a hash, then a controller action, simply put this route handles this model followed by this action. For example…

blog#show = This route shows the entries in the blog model

blog#destroy= This route deletes items entries in the blog model

--

--

Steven Klavins
Steven Klavins

Written by Steven Klavins

Hi, I’m Steven, most call me Steve! I’m a programmer, musician, and artist. This blog contains various tutorials and posts related to software development.

No responses yet

Write a response