How to read rails routes


This time, I would like to explain how to read the routes described when entering the rails routes command.

1. What is routing?

Simply put, it is a "signpost" that specifies the destination of the request.

2. Routing settings

You can set the routing by describing it in the routes.rb file.

Rails.application.routes.draw do
 get 'posts', to: 'posts#index'

3. Check the routing

rails routesYou can check the configured routing by entering the command in the terminal.

4. How to read rails routes

Prefix  Verb  URI Pattern       Controller#Action
posts   GET   /posts(.:format)  posts#index

Prefix ・ ・ ・ URI Pattern with a name and variable Verb ・ ・ ・ HTTP method URI Pattern ・ ・ ・ URL on the Web Controller # Action ・ ・ ・ Controller and action to process the request

By understanding the contents of the above four points, you can grasp the flow of what kind of routine is set and what kind of processing you are trying to perform. Let's understand and enjoy programming together!


Thank you for reading to the end! I hope it will be useful for those who are in trouble or worried about the same part!

Recommended Posts

How to read rails routes
How to write Rails
How to uninstall Rails
[Rails] How to decide the destination by "rails routes"
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
How to use rails join
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[iOS] How to read Carthage
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[rails] How to display db information
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Rails] How to speed up docker-compose
[Rails] How to add new pages
Rails on Tiles (how to write)
[Rails] How to write exception handling?
[Rails] How to install ImageMagick (RMajick)
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails
[Introduction to Rails] How to use render
How to install Swiper in Rails
How to implement search functionality in Rails
How to change app name in rails
How to use custom helpers in rails
[Ruby on Rails] How to use CarrierWave
[Rails] How to upload images using Carrierwave
How to insert a video in Rails
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
[Rails] How to display error messages individually
How to deploy
How to use MySQL in Rails tutorial
How to resolve errors when installing Rails 5.1.3
[rails] How to configure routing in resources
[Ruby on Rails] How to use redirect_to
[rails] How to create a partial template
[Rails 5.x] How to introduce free fonts
How to implement ranking functionality in Rails