Chapter 15. Routing
Rails routing can shock developers who are used to putting their code in files wherever they want to put them. After the directory-based approach of traditional HTML and template-based development, Railsâ highly structured approach looks very strange. Almost nothing, except for a few pieces in the public folder, is anywhere near where its URI might have suggested it was. Of course, this may not be so shocking if youâve spent a lot of time with other frameworks or blogsâthere are many applications that control the meanings of URIs through mechanisms other than the file system.
Note
If you prefer to read âURIâ as the older and more familiar URL,
thatâs fine. Everything works the same here. (And the core method Rails
uses to generate URIs is, of course, url_for
, in the UrlModule
.)
Rails routing turns requests to particular URIs into calls to particular controllers and lets you create URIs from within your applications. Its default routing behavior, especially when combined with resource routes generated through scaffolding, is often enough to get you started building an application, but thereâs a lot more potential if youâre willing to explore Rails routing more directly. You can create interfaces with memorable (and easily bookmarkable) addresses, arrange related application functionality into clearly identified groups, and much, much more.
Whatâs more, you can even change routes without breaking your applicationâs user interface, as the routing ...
Get Learning Rails now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.