19 Oct '13, 3pm
Rails route helpers are brittle via @pivotallabs
TL;DR: Use the resource itself instead of a route helper when representing urls in your Rails application. Route helpers hard code knowledge of model names, making refactoring to polymorphism harder. This is a story about a widely used, and potentially very brittle Rails feature. We have a large Rails application. Our large Rails application has a lot of views. Those views have lots of links and forms. Many of our controller actions have urls in them (for redirection, typically). When we represented a URL in the app, we often used a rails route helper. For example, imagine we had the following routes: namespace :admin do scope module: “admin” do resources :widgets do scope module: “widgets” do resources :gizmos resources :things resources :gadgets end end end end Our app has an admin section. In the admin section, you can manage widgets. Also, widgets have gizmos. When we ...