6.3. Names of Routes

A route should also always have an internal name. In Section 6.2, “get” there is the following route:
home_pong GET /home/pong(.:format)  home#pong
This route has the automatically created name home_pong. Generally, you should always try to work with the name of the route within a Rails application. So you would point a link_to to home_pong and not to /home/pong. This has the big advantage that you can later edit (in the best case, optimize) the routing for visitors externally and do not need to make any changes internally in the application. Of course, you need to enter the old names with :as in that case.


If you want to define the name of a route yourself, you can do so with :as. For example, the line
get "home/pong", :as => "alter_name"
results in the route
alter_name GET    /home/pong(.:format)      home#pong

Updates about this book will be published on my Twitter feed.