« Back to blog

Rails: Named Routes

I found this guide's ( http://guides.rubyonrails.org/routing.html#named-routes) somewhat confusing at first since I had assumed that "map.login" was some formal mapping command.

Instead, I've come to learn that named routes are simply shortcuts for url references in Rails apps. For
example, something like " map.my_history 'home/my_history', :controller => 'home', :action => 'my_history' " creates 2 new methods: my_history_url and hash_for_my_history_url. The former helps with whenever you need a reference to this route and the latter returns a hash used in conjunction with the "url_for" method.

So I should be able to say something like "<%= link_to "My History", my_history_url %>" in other parts of my code.