Explanation of the order of rails routes

Summary for myself

https://qiita.com/gawach/items/4e7460d06f70e3013eea It is summarized in, but I have a different understanding. I will explain it.

⑴
  1 get "posts/:id" => "posts#show"
  2 get "posts/new" => "posts#new"
⑵
  3 get "posts/new" => "posts#show"
  4 get "posts/:id" => "posts#new"
⑶ (Correct code written on Progate)
    get "posts/index" => "posts#index"
    get "posts/:id" => "posts#show" 

⑴ is wrong, and ⑵ is actually correct, which is shown below.

Because the code is prioritized from the top Make sure that certain URLs other than: id come before: id. And the rest of them are subject to: id. Because there are rules like the above If: id is described before URL such as posts / new, an error will occur.

Recommended Posts

Explanation of the order of rails routes
[Order method] Set the order of data in Rails
Explanation of the FizzBuzz problem
[Rails] Check the contents of the object
Check the migration status of rails
Order of processing in the program
The identity of params [: id] in rails
part of the syntax of ruby ​​on rails
[Rails] Change the label name of f.label
Explanation of Ruby on rails for beginners ①
The process of introducing Vuetify to Rails
[No.004] Corrected the order list screen of the orderer
[Rails] How to decide the destination by "rails routes"
[Rails] Button to return to the top of the page
[Ruby on Rails] Until the introduction of RSpec
The order of Java method modifiers is fixed
[Rails] Ranking and pagination in order of likes
A review of the code used by rails beginners
IOTA: [Technical explanation] The whole picture of the remittance bundle.
[rails] After option useful when you want to change the order of DB columns
The world of clara-rules (2)
Docker the development environment of Ruby on Rails project
[Rails] Introduction of PAY.JP
Judgment of the calendar
The world of clara-rules (4)
I summarized the display format of the JSON response of Rails
The world of clara-rules (1)
[Rails] How to change the column name of the table
The world of clara-rules (3)
Rails Tutorial/Significance of Indexing
[Rails] Cancel / change the default password validation of devise
Read the Rails Guide (Overview of Action Controller) again
Rails6: Input the initial data of ActionText using seed
The world of clara-rules (5)
The idea of quicksort
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
[Rails] How to get the contents of strong parameters
SSL in the local environment of Docker / Rails / puma
Roughly the flow of web application development with Rails.
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
I can't get out of the Rails dbconsole screen
Explanation of Ruby on rails for beginners ② ~ Creating links ~
Master the [Rails] scope!
Arrange posts in order of likes on Rails (ranking)
Try using the query attribute of Ruby on Rails
The idea of jQuery
Explanation of Ruby on rails for beginners ⑦ ~ Flash implementation ~
[Rails] Put the same restrictions on multiple pieces of information
[Enum] Let's improve the readability of data by using rails enum
A quick explanation of the five types of static in Java
[Rails] Register by attribute of the same model using Devise
[Rails 6] The save timing of active_strage images has been changed.
(Ruby on Rails6) Display of the database that got the id of the database
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
Rails sorting function implementation (displayed in order of number of like)
Let's summarize how to extend the expiration date of Rails
[Rails] When the layout change of devise is not reflected
[Rails] How to display the list of posts by category
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
[Rails] Where to be careful in the description of validation