Skip to Main Content
Learning Rails
book

Learning Rails

by Simon St. Laurent, Edd Dumbill
November 2008
Beginner content levelBeginner
448 pages
12h 25m
English
O'Reilly Media, Inc.
Content preview from Learning Rails

Chapter 3. Adding Web Style

The application presented in Chapter 2 is pretty appalling, visually. You’re not likely to want to present pages that look like that to your visitors, unless they’re fond of the early-1990s retro look. Rails provides a number of features that will help you make your views present results that look the way you think they should look, and do so consistently.

Note

This chapter will explore Rails features for supporting CSS and HTML, but it can’t be an HTML or CSS tutorial. If you need one of those, try Jennifer Niederst Robbins’ Learning Web Design (O’Reilly, 2007) or David Sawyer McFarland’s CSS: The Missing Manual (O’Reilly, 2006).

I Want My CSS!

Figure 3-1, the result of the last chapter’s coding, is not exactly attractive.

The hello page after the loop executes

Figure 3-1. The hello page after the loop executes

Even this fairly hopeless page, however, can be improved with the bit of CSS shown in Example 3-1.

Example 3-1. A simple stylesheet for a simple page

body { font-family:sans-serif;
  }

h1 {font-family:serif;
  font-size: 24pt;
   font-weight: bold;
   color:#F00 ;
  }

Better CSS would of course be a good idea, but this will get things started. We could put this stylesheet right into the index.html.erb file as an internal style element, but it’s usually easier to manage external stylesheets kept in separate files. As noted earlier, though, Rails has its own sense of where files should go. In this case, stylesheets ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Rails 5

Learning Rails 5

J. Mark Locklear, Eric J Gruber, Barnabas Bulpett
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao
Ruby on Rails® Bible

Ruby on Rails® Bible

Timothy Fisher

Publisher Resources

ISBN: 9780596154943Supplemental ContentErrata