Chapter 2 - Getting Started

Rails pie chart

Introduction

It's time to start building RailsSpace, a social networking website for Ruby on Rails enthusiasts (and whoever else shows up). Eventually, RailsSpace will have many of the features associated with popular social networks such as Facebook and MySpace, with searchable user profiles, an email system, and friends lists. The first part of the book lays a foundation by developing a system for registration, login, and authentication. This system is essential for our purposes, but it's also needed for virtually any user-based web application. In the second part, we'll build a social network on this foundation. Of course, in the process of making this specific type of application, we'll develop many general techniques useful for building other kinds of websites as well.

In this chapter, we'll get started with the application by making the front page of our site, together with a couple of other static pages. Much of what we do in this chapter could be done quite easily with plain HTML files, but even in this extremely simple case Rails still proves surprisingly convenient. It also makes for a gentle introduction to some of the core concepts behind Rails, including Embedded Ruby and the model-view-controller architecture.

Table of Contents

  • 2.1 Preliminaries 13
    • 2.1.1 Setting up your development environment 15
    • 2.1.2 Running with rails 15
    • 2.1.3 Development server 18
  • 2.2 Our first pages 20
    • 2.2.1 Generating a controller 20
    • 2.2.2 The Site controller 22
    • 2.2.3 Rails URLs 24
    • 2.2.4 Changing the route 25
  • 2.3 Rails views 26
    • 2.3.1 Embedded Ruby 27
  • 2.4 Layouts 28
    • 2.4.1 ERb, actions, and instance variables 30
    • 2.4.2 Recap: slicing up a page 32
    • 2.4.3 Adding navigation 32
    • 2.4.4 Hashes 34
    • 2.4.5 Symbols 35
    • 2.4.6 Polishing up link_to 35
    • 2.4.7 Some matters of style 36
    • 2.4.8 Polishing navigation 37
    • 2.4.9 Finding things for yourself 37
  • 2.5 Developing with style 38

Source Code

Errata

As of the first printing, these are the known corrections:

  1. p. 19, Fig. 2.4. The Rails version (1.1.2) is out of date. It should read 1.2.3.
  2. p. 24. gemserver should be gem_server
  3. p. 26 At the top of the page, both occurrences of map.connect " should be map.connect '' (one double quote to two single quotes)
  4. p. 31. The two occurrences of @contentforlayout in the first full paragraph should be @content_for_layout
  5. p. 31. In Listing 2.11, "Welcome to RailsSpace!" should be "RailsSpace"
  6. p. 33. linkto should be link_to

Screencast

LESSON 2: Getting Started