Ruby on Rails Enterprise Application Development::
Plan, Program, Extend
www.PACKTPUB.com  FREE ONLINE EDITION: Read full chapters online, download free samples from the book and more...
Book Contents Index > Chapter 4
Introduction
1: Introduction
2: The Initial Problem
3: Laying the Foundations
4: Working with Rails Free Chapter
5: Building the User Interface
6: Into Production
7: Improving the User Experience
8: Extending the Application
9: Advanced Deployment

10: Down the Track

Appendix A: Running Your Own Gem Server

Index

Latest Updates

Free Chapter:

Chapter 4: Working with Rails [ 1.7 MB PDF]

Code Download

Contact us

Chapter 4: Working with Rails

It's now time to get our hands dirty and start developing a Rails application. In Chapter 2, we saw the data structure for the Intranet application, which Acme plans to build. In this chapter, we'll start building this application: in effect, we will be looking over Rory's shoulder as he develops Intranet. For the purposes of this chapter, Linux will be used as the development platform; but as all of the tools used are cross-platform, the instructions should port easily to Windows and Mac. Specifically, we'll focus on turning the abstract data structure for Intranet into a Rails application. This requires a variety of concepts and tools, namely:

  • The structure of a Rails application.
  • Initializing an application using the rails command.
  • Associating Rails with a database.
  • The built-in utility scripts included with each application.
  • Using migrations to maintain a database.
  • Building models and validating them.
  • Using the Rails console to manually test models.
  • Automated testing of models using Test::Unit.
  • Hosting a project in a Subversion repository.
  • Importing data into the application using scripts.

You may have noticed that we haven't mentioned much about the application's user interface. That's because we can build a large part of the application without having to code HTML. We'll see how to add a front-end in the next chapter, but for now we will concentrate on the data side of things.

Chapter 4: Working with Rails

  • The World According to Rails
    • Model-View-Controller Architecture
    • Convention over Configuration
      • Rails and MVC
  • Setting Up a New Rails Application
    • Using Mongrel to Serve Your Application
  • Connecting Rails to a Database
    • Creating a Database and System Account
    • Setting Up a Database Connection
      • Configuring the Rails Environments
      • Testing the Database Connection
      • Troubleshooting a MySQL Connection
  • ActiveRecord, Migrations, and Models
    • Model == Table
    • Which Comes First: The Model or The Table?
    • Building a Model with Migrations
      • Converting a Data Structure into a Migration
      • Defining Columns in Migrations
      • Other Operations Available in a Migration
    • Running a Migration
    • Rolling Back to a Previous Version of the Database
  • The Scaffold
  • Completing the Database
    • The companies Table
    • The addresses Table
    • Generating the Remaining Tables
  • Models in Detail
    • Creating New Records in a Table via Models
    • Finders
      • Finding All of the Records in a Table
      • Virtual Attributes
      • Sorting Records
      • Finding a Single Record
      • Finding Records Matching Search Criteria
      • Finding Records Using Attribute-Based Finders
      • Finding Records by Raw SQL
      • Writing a Custom Finder
      • Viewing the SQL
      • Viewing Logs in Eclipse
    • Validation
      • Validating People
      • Validating Companies
      • Validating Addresses
      • Other Types of Validation
    • Testing
      • Setting Up for Testing
      • Anatomy of a Test Case
      • What Should be Tested?
      • Fixtures
      • Tests for the Person Model
      • Other Types of Assertion
      • Becoming Driven by Testing
    • Associations between Models
      • Parent to children (one-to-many): addresses to people
      • Parent to child (one-to-one): addresses to companies
      • Parent to children (one-to-many): companies to people
      • Many-to-many relationships
      • Dependencies
      • Testing Associations
  • Putting the Project into Context
    • Storing a Project in Subversion
      • Ignoring Temporary Files
      • Committing Code to the Repository
    • Processing Data
      • Exporting the Data from Outlook
      • Mapping a Text File to Database Tables
      • Coding the Script
  • Summary
   

 

Paperback 528 pages
Released: October 2007
ISBN: 1847190855
ISBN 13: 978-1-847190-85-7

     

 




View the book details
on PacktPub.com

 


 

  This website is owned and maintained by Packt Publishing Ltd, 2007. All rights reserved. Terms and Conditions