You are previewing Ruby on Rails For Dummies®.
O'Reilly logo
Ruby on Rails For Dummies®

Book Description

Quickly create Web sites with this poweful tool

Use this free and easy programming language for e-commerce sites and blogs

If you need to build Web and database applications quickly but you don't dream in computer code, take heart! Ruby on Rails was created for you, and this book will have you up and running in no time. The Ruby scripting language and the Rails framework let you create full-featured Web applications fast. It's even fun!

Discover how to

  • Install and run Ruby and Rails

  • Use the RadRails IDE

  • Create a blog with Ruby

  • Connect your Web site to a database

  • Build a shopping cart

  • Explore Ruby's syntax

Table of Contents

  1. Copyright
  2. About the Author
  3. Dedication
  4. Author's Acknowledgments
  5. I. Nuts and Bolts
    1. In this part . . .
    2. Introduction
      1. How to Use This Book
      2. Conventions Used in This Book
      3. What You Don't Have to Read
      4. Foolish Assumptions
      5. How This Book Is Organized
        1. Part I: Nuts and Bolts
        2. Part II: Creating Code
        3. Part III: Real Rails
        4. Part IV: The Part of Tens
      6. Icons Used in This Book
      7. Where to Go from Here
    3. 1. Welcome to the World of Ruby on Rails
      1. The Software Development Process
        1. Agility
        2. Databases and the World Wide Web
        3. Throwing frameworks at the problem
      2. Along Comes Ruby on Rails
        1. Why Ruby?
          1. Ruby is dynamically typed
          2. Ruby is interpreted
          3. Ruby is reflective
          4. Ruby is object‐oriented
        2. Why Rails?
          1. Convention over configuration
          2. Don't Repeat Yourself (DRY)
      3. Let's Get Going
    4. 2. Installing the Software
      1. Six Pieces of Software
      2. Installing the Ruby Interpreter
        1. Testing the Ruby installation
        2. Troubleshooting the Ruby installation
      3. Installing Rails
      4. Installing Java
      5. Installing RadRails
        1. Creating a RadRails shortcut on your desktop
        2. Testing RadRails
        3. Troubleshooting the RadRails installation
        4. Configuring RadRails
      6. Installing MySQL
      7. Installing MySQL Administrator
        1. Testing your MySQL installation
        2. Troubleshooting your database connection
          1. Is the database server running?
          2. Are the server and the administrator programs using the same settings?
    5. 3. Details on Rails
      1. Creating a Database
      2. Creating a New Ruby on Rails Project
      3. Running Your New Rails Project (Already!)
      4. Creating a Model
      5. Creating a Database Table
      6. Creating a Scaffold
      7. Using the New Web Interface
    6. 4. Using RadRails
      1. Words, Words, Words
        1. What's inside a view or an editor?
        2. Understanding the big picture
      2. Some Common RadRails Tasks
        1. Changing the perspective
        2. Showing a view
        3. Using a wizard to create something
        4. Using the Generators view to create something
        5. Editing an existing file
        6. Running a Ruby program
        7. Visiting a URL
        8. Customizing RadRails
      3. Troubleshooting the Run of a Ruby Program
        1. Does your Ruby code have a syntax error?
        2. Does your Ruby code have a semantic error?
        3. Did you tell RadRails where to find a Ruby interpreter?
        4. Did you point RadRails to the correct location of the Ruby interpreter?
  6. II. Creating Code
    1. In this part . . .
    2. 5. Ruby One's Day
      1. Hello, Again
        1. A glimpse of a Ruby method
        2. Variables and values
        3. Ruby strings
      2. Working with Values
        1. Displaying values
        2. Assigning values
      3. Going with the Flow
        1. Getting input from the keyboard
        2. Using keywords
        3. Flowing the other way
        4. Going with the glow (or glowing with the flow)
      4. Bunches of Things
        1. Arrays
        2. Hashes
          1. Hashes and loops
          2. Writing the fine print
      5. Using Methods
        1. Methods, methods everywhere
          1. A method with no parameters
          2. A method that displays a value
          3. A method that returns a value
          4. A method call with a block
          5. A block with three parameters
          6. A method with a variable number of parameters
        2. Please pass the hash
        3. What's the symbolism?
          1. Comparing and displaying symbols
          2. Using symbols as hash keys
    3. 6. Ruby Two's Day
      1. Objects and Classes
        1. Creating objects
        2. Adding another file's code to your own file's code
        3. Classes, objects, and database tables
      2. Objects Have Methods
        1. Ruby's handy iterators
        2. Finding iterators where you least expect them
      3. Enhancing Classes
        1. Open classes
        2. Being selfish
        3. Defining subclasses
          1. Creating an instance of a subclass
          2. Using a subclass's method
      4. Creating a Module
    4. 7. Weaving the Web
      1. The Working of the Web
        1. The Web developer's point of view
        2. The Hypertext Transfer Protocol
        3. Web pages
      2. Your HTML Starter Kit
        1. Start tags
        2. End tags, empty tags, and paired tags
        3. If it feels good, do it
        4. Entities
        5. Comments and declarations
      3. HTML Elements
        1. Displaying images
        2. Using tables to align things
        3. Creating an HTML form
        4. Using form elements
          1. Creating a text area
          2. Using an option selector
          3. Creating check boxes
          4. Mining for hidden fields
  7. III. Real Rails
    1. In this part . . .
    2. 8. Action‐Packed Adventures
      1. Model/View/Controller
        1. Creating a controller and a view
        2. Why you shouldn't rename files
      2. The Rails Way of Life
        1. Convention over configuration
        2. Don't Repeat Yourself (DRY)
      3. Writing What You Want Where You Want It
        1. Sending text to the console
        2. The art of Web server redirection
        3. Making the controller do the work
      4. The Controller Shakes Hands with the View
        1. Using parameters
        2. Getting parameters from a form
      5. Dividing the Work of the View
        1. Creating and using a partial (a partial what?)
        2. A view's little helper
    3. 9. Some Things You Can Do with Models
      1. A Web Site for Photos
      2. Programming with a Rails Model
        1. Using Active Record
        2. Requiring a gem
        3. Connecting to the database
        4. Displaying data
      3. Modifying a Database
      4. More Rails Programming Tricks
        1. Deleting rows
        2. Adding rows
        3. Finding rows
        4. Using SQL
        5. Using id numbers
    4. 10. I've Been Working on the Rails Code
      1. Displaying an Image
        1. Creating code
        2. Understanding the code
          1. The shallow version
          2. Diving into the depths
        3. Passing photos from place to place
          1. A link_to method creates an anchor element
          2. Rails finds a particular photo
          3. Using JavaScript
      2. Importing Files
        1. Importing files the easy way
        2. Importing files the geeky way
    5. 11. Image Is Everything
      1. Enhancing Your Project's Code
        1. Follow the book's longest step list
        2. Know the flow
      2. Understanding the Enhanced Code
        1. Creating a database table
        2. Moving on to more code . . .
        3. Creating a file input field
        4. Creating a Photo instance
        5. Reading the image bits
        6. Composing an image tag
        7. Sending image bits to the visitor's browser
        8. Whew!
    6. 12. More Model Magic
      1. Blogging Your Dreams
      2. Validating the Visitor's Input
      3. Adding Comments
      4. Adding Keywords
        1. Connecting dreams with keywords
        2. How the Rails code does what it does
          1. Removing a keyword
          2. Using a drop‐down list to add a keyword
          3. Using check boxes to add keywords
    7. 13. Cool Things on Rails
      1. Using Ajax
        1. Refresh part of a page, not the entire page
        2. Incorporating Ajax into a Rails page
      2. Sending E‐Mail
        1. Don't blame me if it doesn't work
        2. Rails mail
      3. Creating and Consuming Web Services
        1. How to avoid screen scraping
        2. Building a Web service using Ruby on Rails
  8. IV. The Part of Tens
    1. In this part . . .
    2. 14. Ten (Times Two) Great Web Sites
      1. Ten Ruby Sites
        1. Documentation
        2. Open source Ruby projects
        3. Starting points for Ruby resources
        4. Discussing Ruby
        5. A weekly challenge
        6. Add‐ons for Ruby
        7. Meet people
        8. Write Ruby code on a desert island
        9. How to be multilingual
        10. Agile development
      2. Ten Rails Sites
        1. Straight from the source's mouth
        2. Find a Web host
        3. Get hooked on RadRails
        4. Documentation
        5. Discuss Ruby on Rails
        6. A Rails‐friendly operating system
        7. Read the latest news
        8. Steal some code
        9. Brush up on SQL
        10. The seminal Ajax document
    3. 15. Ten Features That Set Ruby Apart
      1. Hashes
      2. Open Classes
      3. Duck Typing
      4. Modifiers
      5. Blocks
      6. Everything Is an Object
      7. Objects Might Have Their Own Methods
      8. Mixins
      9. Built‐In Unit Testing
      10. Built‐In Reflection
    4. 16. Ten Pivotal Ruby on Rails Concepts
      1. Don't Repeat Yourself (DRY)
      2. Convention over Configuration
      3. Model/View/Controller (MVC)
      4. Agile Development
      5. Dynamic Discovery of a Database's Characteristics
      6. Object‐Relational Mapping (ORM)
      7. Using Generators
      8. Create, Read, Update, and Delete (CRUD)
      9. Using Migrations
      10. Using Partials
    5. 17. Ten Ways to Override Rails Defaults
      1. Overriding the Database Name
      2. Overriding a Database Table Name
      3. Overriding a Controller Name
      4. Overriding the Name of a Table's Primary Key
      5. Using Singular Nouns
      6. Creating Irregular Plurals
      7. Overriding a Default Layout
      8. Creating Additional Web Pages
      9. Modifying the Meanings of URLs
      10. Changing the Server Environment