Performance: Route definition in routes.rb
This affects the initial server response time and client navigation speed by determining how requests are matched to controller actions.
Rails.application.routes.draw do resources :posts end
Rails.application.routes.draw do get '/posts/index', to: 'posts#index' get '/posts/show/:id', to: 'posts#show' get '/posts/new', to: 'posts#new' post '/posts/create', to: 'posts#create' get '/posts/edit/:id', to: 'posts#edit' patch '/posts/update/:id', to: 'posts#update' delete '/posts/destroy/:id', to: 'posts#destroy' end
| Pattern | Route Table Size | Matching Time | Server Response Impact | Verdict |
|---|---|---|---|---|
| Manual individual routes | Large | High (linear with routes) | Slower LCP due to longer routing | [X] Bad |
| Resourceful routes | Compact | Low | Faster LCP with efficient routing | [OK] Good |
routes.rb file in a Rails application?/home that maps to the index action of the pages controller?get 'url', to: 'controller#action'.get '/home', to: 'pages#index'.routes.rb:
resources :articles, only: [:index, :show]What URLs will be available and which controller actions will they map to?
resources with only optionindex and show actions.index and showindex maps to GET /articles, show maps to GET /articles/:id.get '/profile', controller: 'users', action: 'show'
to: 'controller#action', not separate keys.to: and incorrectly uses separate keys.routes.rb?resources block inside another.comments inside posts using a block.Pass the test and this pattern moves unknown