Ruby on Rails Enterprise Application Development: Plan, Program, Extend

Ruby on Rails Enterprise Application Development: Plan, Program, Extend
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 45%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
save 17%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Create a non-trivial, business-focused Rails application
  • Solve the real-world problems of developing and deploying Rails applications in a business environment
  • Apply the principles behind Rails development to practical real-world situations


Book Details

Language : English
Paperback : 528 pages [ 235mm x 191mm ]
Release Date : October 2007
ISBN : 1847190855
ISBN 13 : 9781847190857
Author(s) : Elliot Smith, Rob Nichols
Topics and Technologies : All Books, Web Development, Open Source

Table of Contents

Chapter 1: Introduction
Chapter 2: The Initial Problem
Chapter 3: Laying the Foundations
Chapter 4: Working with Rails
Chapter 5: Building the User Interface
Chapter 6: Into Production
Chapter 7: Improving the User Experience
Chapter 8: Extending the Application
Chapter 9: Advanced Deployment
Chapter 10: Down the Track
Appendix A: Running Your Own Gem Server
  • Chapter 1: Introduction
    • Why this Book?
    • Why Develop?
    • Why a Client/Server Based Web Application?
    • But why Ruby on Rails?
      • Rails Handles Menial Tasks
      • Clear Code
      • Text Based File
      • Open Source
      • Plentiful Documentation
      • Built-in Safe Test Environment
    • Ruby on Rails in Detail
    • Summary
  • Chapter 2: The Initial Problem
    • A Normal Day in the Office
    • Examining the Data
    • Data Objects
      • Database Table Design Rules
    • Separating the Data
    • Naming Conventions
      • Use Meaningful Names
      • Use a Consistent Naming Convention
      • Ruby on Rails Naming Conventions
        • Constants and Classes
        • Variables
        • Methods and Properties
        • Special Method and Property Suffixes
        • Reserved Words
    • Back to the Data
    • Review the Result
      • Project Preparation Steps
    • How Good is the Source Data?
    • Tracking Who does What
      • No Log-On and No Authentication
      • Simple Password Access
      • User Log-On
      • Recording Access History
      • Access Control for Rory's Application
    • Data Validation
      • The Minimum Required Data is Entered
      • Each Record can be Uniquely Identified
      • Identify Fields that Need to Have a Particular Format
      • References to Data in Other Tables Point to Actual Data
    • Rory's Data
      • Person
      • Company
      • Address
    • Summary
  • Chapter 3: Laying the Foundations
    • Supporting Rails Development
    • Addressing the Challenges
    • Setting Up a Rails Stack
      • Installing a Rails Stack Using a Bundle
    • Installing a Custom Rails Stack
      • Installing Ruby and Rubygems
        • Ruby on Windows
        • Ruby on Linux
        • Ruby on Mac OS X
      • Installing Rails
        • A Note on Rails Documentation
      • Other Libraries
        • Capistrano for Easier Deployment
        • Mongrel: A Better Way to Run Rails Applications
      • Choosing a Database Platform
        • Installing MySQL
        • Checking Your MySQL Installation
        • MySQL GUI Tools
        • Ruby-MySQL: Making Ruby and MySQL Work Better Together
      • Installing an IDE
        • Eclipse
        • EasyEclipse
      • Instructions for Masochists
      • In the Back Rooms at Acme…
    • Setting Up a Team Server
      • Quick Gem Installation
    • Remote Access via SSH
      • Adding Users
    • Version Control with Subversion
      • Subversion Standard Practices
      • Setting Up a Subversion Repository
      • Setting Up a Project in Subversion
      • Browsing Subversion from Eclipse
      • Other Subversion Clients
    • Using Other People's Servers
    • Back at Acme
  • Summary
  • 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
  • Chapter 5: Building the User Interface
    • Controllers and Views: A Recap
    • Creating a Simple Controller and Its Views
      • Views and Layouts
        • Adding a View to the Application
        • Displaying Model Instances in a View
        • Pagination
        • Linking to Another View
        • Adding a Layout
        • Adding a Stylesheet
    • Adding a Controller for Companies
      • Create the CompaniesController
      • Create the Index View
      • Test It!
      • Summary
    • Advanced View Techniques
      • Custom Helpers
        • Default Messages for Empty Fields
        • Date Formatting
      • Showing Associated Records
        • Refining Using a Helper
        • Showing an Address with a Partial
      • Rendering Pagination Links with a Partial
      • Adding a Menu
    • C*UD (Create, Update, Delete)
      • Creating a Person
        • Refining with a Helper
        • Validation Errors
        • The Flash
        • Finishing Touches
      • Updating a Person
      • Opportunities for Refactoring
        • Using Filters
        • Creating Application-Level Controller Methods
      • Deleting a Person
      • Adding Edit and Delete Links to a Person's Profile
    • Editing Multiple Models Simultaneously
      • Adding a New Address for a Person
        • Using Functional Testing for Complex Actions
      • Updating a Person and Their Address
      • Summary
    • Fleshing Out Companies and Addresses
      • Managing Companies
        • Stubbing Out the Navigation
        • A Shared View to Confirm Deletions
        • Attaching a Person to a Company
        • Creating and Updating Companies
      • Managing Addresses
        • Adding a Callback to Company Deletions
        • A Very Quick Interface for Addresses
    • Summary
  • Chapter 6: Into Production
    • An Application Ready for Production
    • The Application Server
      • Memory
      • Central Processor Unit–CPU
      • Hard Disks
      • Network Interface Card–NIC
      • Don't Forget Backup
      • Your First Production Server
    • Setting up the Server
      • Installing Ruby and Rails
      • Copying the Files to the Server
      • Using Subversion to Transfer the Application to the Production Environment
      • Excluding Files from the Repository
      • The Production Database
      • Separating Development and Production Databases
        • Localhost database–single database.yml
        • Separate Development and Production database.yml files
        • Using Migration in Production
        • The Rails Database User
      • The Web Server
        • Mongrel
        • Mongrel Service on Windows
        • Limitations of Mongrel
        • Mongrel behind Apache
        • Installing Apache
        • Apache on Linux and Mac OS X
        • Apache on Windows
        • Domain Name System (DNS)
        • Configuring Apache to Act as a Proxy for a Rails Application
    • Rory's Production Installation
      • Using Two Host Names to Simplify Routing
      • Rory Puts his Intranet Application into Production
    • Errors in Production
      • Slow List Rendering due to Placement of Additional Data Processing in Loop
        • Symptom
        • Cause
        • Fix
      • Application Error Following the Transferring of New Code to Production
        • Symptom
        • Cause
        • Solution
    • Back Up Rails
      • Backing Up the Code Repository
      • Back Up the Database
      • Combining Your Backup Scripts
    • Summary
  • Chapter 7: Improving the User Experience
    • Easy Access to the Application
      • Use Routes to Simplify the Entry Point URL
      • Build a Fast, Clear Home Page
    • Users Need to be Able to Find Items Easily
      • Use the Index View as the Core of the Search View
      • Search–The First Attempt
      • Do Not Trust User Input
      • Handle Nothing
      • Users Need to be Able to Search Without Knowing Exactly What They Are Looking for
      • A Less Specific Search
      • Case Insensitive Searches
    • Adding AJAX to the Mix
      • Make the AJAX Libraries Available to our Rails Application
        • Enhancing Search with Auto-complete
        • Auto-complete—Wow!, but...
      • Use of AJAX—the Lessons Learned from Auto-Complete
    • Show and Hide Company Address Using link_to_remote
      • A Simple link_to_remote
        • A DOM Object to Update
        • Create a say_hello Action
      • Increasing the Functionality of link_to_remote
        • Show and Hide
        • Alternating link_to_remote Elements
        • Alternative Actions
        • Debugging JavaScript
        • Show/Hide within the Company Index List
      • Using AJAX to Edit a Field in Line
        • Render an AJAX Form via link_to_remote
      • A Little Drag and Drop
        • Make an Element Draggable
        • A Place to Drop the Element
      • Further AJAX
    • Help!
      • RDoc–Documentation for the Developer
      • Help for the User
        • Instiki Wiki Help
        • The Best User Help Systems
    • Keep Talking to Users
    • Summary
  • Chapter 8: Extending the Application
    • Dealing with User Feedback
    • Adding a Search Facility
    • Handling Errors
      • Catching Missing Record Errors
      • Catching UnknownAction and Routing Errors
      • Catching General Application-Level Errors
      • Catching "Rails has Fallen Over" Errors
    • Adding an Authentication System
      • Cookies and Sessions in Rails
      • Building the Authentication System
        • The User Model
        • Displaying the Login Form
        • Checking Submitted Credentials
        • Logging Out
        • Protecting Actions
    • Adding Simple Task Tracking
      • The Task Model
      • The Tasks Controller
      • Task Views
      • Showing Tasks for a Person
      • Redirecting to a Person after Adding or Editing a Task
      • Redirecting after a Deletion
      • Handling the Cancel Link
      • Setting a Default Person for a New Task
      • Summary
    • Uploading and Attaching Files
      • Using Plugins
      • Using acts_as_attachment for File Uploads
      • Managing File Attachments for a Task
        • Adding a Form for Attaching a File to a Task
        • Adding a File Attachment to a Task
        • Listing File Attachments for a Task
        • Deleting File Attachments for a Task
        • Protecting File Attachment Actions
    • Summary
  • Chapter 9: Advanced Deployment
    • Deployment with Capistrano
      • Getting Started with Capistrano
        • A Complete Deployment Recipe
      • Preparing the Production Database
      • First Deployment
      • Migrating the Production Database
      • Running Other Commands on the Server with invoke
      • Managing Mongrel from Capistrano
      • Centralizing File Uploads
        • Upgrading the Application
        • Cleaning Up Obsolete Releases
      • Downgrading the Application
    • Troubleshooting Deployment
      • Incompatible Rails Versions
      • Missing Libraries
      • Incorrect Subversion Password or Repository Permissions
      • User Doesn't Have SSH Access to the Server
      • Inaccessible Application Server
      • Inaccessible Database Server
      • Dealing with the Inexplicable
      • Getting Back to a Clean Slate
    • Housekeeping
      • Starting Mongrel Automatically
      • Clearing Out Stale Sessions
      • Keeping Log Files Manageable
        • Reducing Log Detail
    • Optimizing a Rails Application
      • Finding Bottlenecks
        • Controller Action Profiling Using around_filter
        • Profiling Everything
        • The Rails Profiler
      • Improving Application Performance with Caching
        • How Cache Elements are Named
        • Deciding What to Cache
        • Preparing for Caching
        • Page Caching
        • Action Caching
        • Fragment Caching
        • Fragment Caching for Actions
        • Avoiding Database Calls for Cached Fragments
        • Clearing out the Cache
      • Optimizing How Rails Uses the Database
        • Ordering for Eager Loading
      • Scaling Your Rails Infrastructure
        • Using Apache to Serve Static Assets
        • Proxying to a Mongrel Cluster
      • Advanced Scaling
    • Summary
  • Chapter 10: Down the Track
    • Going off the Rails
    • SQL
      • Gathering Data from a Daughter Object's Daughter
        • Using a model’s ActiveRecord connection
        • Using GROUP BY to Summarize Data
        • A Deeper Look at Aggregate Functions
    • Business Processes
      • To Be Successful, Build Successful Business Applications
        • Automate Simple Repetitive Jobs
        • Rapid and Detailed Reporting
        • Ensure Customers Pay for the Goods and Services that the Business Provides
        • Review of Business Activity Examples
      • Dealing with Success
        • Just Because You Can, Doesn't Mean You Should
        • Bought in solutions Provide their Own Opportunities
        • Ensure There is Time to Complete Each Task
    • The Final Destination

Elliot Smith

Elliot Smith has worked in IT since 1996, and currently works at Talis, as a software developer working on library systems. Prior to that, he worked at OpenAdvantage (an open-source solutions center) as a business analyst; as a learning technologist and web developer at the University of Birmingham, England; and as a technical writer for Armada Computer Publications. He has an M.Sc. in Artificial Intelligence and a Ph.D. in Computer Science from the University of Birmingham. His personal website is

He thanks Nicola, his wife, for giving him the time and space to write a book; Madeleine, his daughter, for keeping him sane while doing it; and Rob Nichols for giving him the opportunity in the first place.

Rob Nichols

Rob Nichols first started using computers during his apprenticeship at Rolls-Royce in the early 1980s. At 23 he decided to change direction and started a degree in Geology and Geography at Cardiff University. By 1995 he had gained a Ph.D. from Bristol University, studying the behavior of quicksand. During his time in Bristol and in a subsequent lectureship at Leeds University, he started using the fledgling Internet to communicate with co-workers, gather information, and present Geological information in the form of his first web pages. Following his return to Britain from a lectureship in U.S.P. Fiji, Rob found himself without another lectureship position to go on to. So, changing direction again, he started working for a U.K. computer manufacturer, where he rose to the position of Engineering Manager, managing a team of seventy maintenance and networking engineers, and support staff. Following the collapse of the U.K. computer market in 2002 he moved on to the role of IT manager for a small business providing products and services to the water industry. In this role, Rob has had great success developing intranet-based business applications that streamline business processes, save time, and increase efficiency. In so doing he has transformed the IT department from a business cost to a profit generator by reducing costs and thereby increasing margins. When not working with computers, Rob and his wife reside happily in a small Midlands town in England, where he writes scripts for the local movie-makers club, and photographs the local wildlife.

For Diane, for putting up with my disappearances into the study to “work on the book”.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Ruby on Rails Enterprise Application Development: Plan, Program, Extend +    Haskell Data Analysis Cookbook =
50% Off
the second eBook
Price for both: $43.05

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Creating a new Rails application
  • Installing an IDE for Rails
  • Connecting Rails to a database
  • Utilizing Rails' Model-View-Controller components
  • Setting up Mongrel with Apache
  • Adding Ajax to your Rails application
  • Backing up Rails applications
  • Adding an authentication system to your application
  • Optimizing Rails applications using caching
  • Scaling up your Rails production infrastructure using Apache, Mongrel, and load balancing

Chapter 1 provides an overview of the book. You will learn why Ruby on Rails should be used in preference to the multitude of other programming and scripting frameworks for developing database-driven web applications.

In Chapter 2, you will learn about some of the conventions used in Rails, and the Rails framework will be introduced. We describe some methods of controlling and logging user access and discuss their merits and limitations. We also discuss data validation and user input control via form design in this chapter.

Chapter 3 outlines how to lay some firm foundations for a sustainable Rails development project. The core of this is obviously the Rails stack itself. You will learn how to install and configure this in some detail. The chapter recommends a few of the technologies closest to the heart of Rails, which can readily be used to support your development work.

Chapter 4 will help you build from an idea and an expectant Rails installation to a fully-fledged data model, populated from an external data source, with full validation and unit test suite. This chapter also provides examples of how to integrate the application with external data sources, and how to share code development across a team.

Chapter 5 describes how to build a web interface on top of the models developed earlier. You will learn about creating a controller from scratch, how to add style sheets, writing complex controller actions to update multiple models simultaneously, and using pagination.

Chapter 6 describes how to set up a Rails production environment. In particular, it covers the decisions you will need to make to successfully get your business application up and running. Some coverage of error handling is presented, and we describe some systems that will make it easier to back up and restore your application.

Chapter 7 concentrates on the tools you can use to improve the user experience. These include providing links into the application, providing search tools, enhancements to the user interface, and providing help to the users.

Chapter 8 aims at showing more of the depth and usefulness of Rails, while at the same time demonstrating how to extend an existing application with new functionality.

Chapter 9 discusses advanced deployment of your application. You will learn how to deploy your application with Capistrano. You will also learn about troubleshooting deployment and optimizing your Rails applications.

Chapter 10 covers how you can improve your Rails skills further, and suggests alternative skills that complement Ruby on Rails, thereby broadening your skill set.

In Detail

All businesses have processes that can be automated via computer applications, thereby reducing costs and simplifying everyday operations. This book demonstrates that a modern web application framework makes an ideal platform for such applications. It shows how the attributes that make the Rails framework so successful for Internet applications also provide great benefit within a business intranet. These attributes include easy roll-out and update of applications, centralized processing and data handling, simple maintenance, straightforward code development, and scalability.

Ruby on Rails is an open-source web application framework ideally suited to building business applications, accelerating and simplifying the creation of database-driven websites. Often shortened to Rails or RoR, it provides a stack of tools to rapidly build web applications based on the Model-View-Controller design pattern.

This book covers topics such as installing Ruby, Rubygems, and Rails on Windows, Linux, and Mac OS X; choosing and installing a database; installing an IDE for Rails development; setting up a Subversion repository to manage your code; creating a new Rails application; understanding Rails models; understanding controllers and views; improving user interfaces with Ajax; using Rails plugins to manage file uploads; using Capistrano to manage application deployment; techniques for scaling Rails applications, such as caching and using Apache to proxy through to the Mongrel server. The example application is straightforward to develop, easy to roll out, and simple to maintain.

This book is aimed at developers who already have some familiarity with the Ruby on Rails framework and who want to move on from the basic tutorials. In particular, it is aimed at those who wish to use the unique attributes of Rails to develop and roll out business applications. It concentrates on application development as a whole process, and is intended to complement existing Rails tutorials.

Read the Ruby on Rails Free Online Edition


This book concentrates on application development as a whole process and is intended to complement existing Rails tutorials. Each chapter deals with a key feature or functional area of a complex, full-scale Rails application.

Who this book is for

This book is aimed at developers who want to find out how to rapidly build easily-deployed, easily-supported business applications. It is for developers who have learned Ruby on Rails, probably from one of the tutorial books, and want to apply that knowledge to effectively build full, realistic applications.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software