Chapter 2. Rails on the Web
Is fear preventing you from taking action? Acknowledge the fear, watch it, take your attention into it, be fully present with it.
Eckhart Tolle, The Power of Now
Now that you have Rails installed, itâs time to make Rails do somethingânot necessarily very much yet, but enough to show you what happens when you make a call to a Rails application, and enough to let you do something to respond when those calls come in. Thereâs a long tradition in computer books of starting out with a program that says âhelloâ to the programmer. Weâll follow that tradition and pursue it a bit further to make clear how Rails can work with HTML. Youâre welcome, of course, to make Rails say whatever youâd like.
Note
The work in this chapter depends on the hello application created in Chapter 1. If you didnât create one, go back and explore the directions given there. You can also find the files for the first demonstration in ch02/hello01 of the downloadable code.
Creating Your Own View
Saying âhelloâ is a simple thing, focused exclusively on putting a message on a screen. To get started, we can post that message using a view including HTML that will get sent to the browser.
Rails actually wonât let you create views directly. Its controller-centric perspective requires that views be associated with controllers. While that might seem like a bit of an imposition, itâs not too hard to work around.
Creating anything in Rails requires going to the command ...
Get Learning Rails 5 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.