Performance: Named routes and path helpers
This affects how quickly URLs are generated and reduces runtime string concatenation during page rendering.
link_to 'Profile', user_path(user)link_to 'Profile', '/users/' + user.id.to_s
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual string concatenation for URLs | 0 | 0 | 0 | [X] Bad |
| Using named route path helpers | 0 | 0 | 0 | [✓] Good |
config/routes.rb?get '/url', to: 'controller#action', as: 'name' format.get '/dashboard', to: 'home#dashboard', as: 'dashboard', what does dashboard_path return?dashboard_path helper returning the URL path string.dashboard_path returns '/dashboard'.get '/items', to: 'items#index', as: items_pathas: option expects a symbol or string name, not a method call like items_path.as: :items or as: 'items' to create items_path helper./users/:id/edit. Which route definition and helper usage is correct?get '/users/:id/edit', to: 'users#edit', as: 'edit_user'; Helper: edit_user_path(5) uses string for 'as:' and calls edit_user_path(5) which is correct. Route: get '/users/:id/edit', to: 'users#edit', as: :edit_user; Helper: edit_user_url uses symbol but calls edit_user_url without argument, which is incomplete.get '/users/:id/edit', to: 'users#edit', as: 'edit_user'; Helper: edit_user_path(5) [OK]Pass the test and this pattern moves unknown