Beginning Rails: From Novice to Professional


Beginning Rails is the practical starting point for anyone wanting to learn how to build dynamic web applications using the Rails framework for Ruby. You?ll learn how all of the components of Rails fit together and how you can leverage them to create sophisticated web applications with less code and more joy.

This book is particularly well suited to those with little or no experience with web application development, or who have some experience but are new to Rails. Beginning ...

See more details below
$25.89 price
(Save 26%)$34.99 List Price
Other sellers (Paperback)
  • All (44) from $1.99   
  • New (19) from $1.99   
  • Used (25) from $1.99   
Sending request ...


Beginning Rails is the practical starting point for anyone wanting to learn how to build dynamic web applications using the Rails framework for Ruby. You’ll learn how all of the components of Rails fit together and how you can leverage them to create sophisticated web applications with less code and more joy.

This book is particularly well suited to those with little or no experience with web application development, or who have some experience but are new to Rails. Beginning Rails assumes basic familiarity with web terms and technologies, but doesn't require you to be an expert.

Topics include:

  • A gentle introduction to the Ruby programming language
  • Installing Ruby and Rails on a Mac, Linux, or Windows system
  • The philosophy behind Rails and why it matters
  • The Model-View-Controller architecture
  • The basics of relational databases and SQL
  • Setting up a MySQL database and creating a schema with migrations
  • Experimenting with your live application in the Rails console
  • Creating rich relationships between your models
  • Using controllers and templates properly
  • Leveraging helpers to keep your templates clean and logic free
  • Adding Ajax and visual effects to enrich your user interfaces
  • JavaScript with Prototype and
  • How to send and receive mail from your application
  • Using and creating your own plug-ins
  • Ensuring your code against Murphy’s Law through writing tests
  • Using Capistrano to deploy your application

Rather than delving into the arcane details of Rails, the focus is on the aspects of the framework that will become your pick, shovel, and axe. Part history lesson, part introduction to object-oriented programming, and part dissertation on open source software, Beginning Rails doesn’t just explain how to do something in Rails, it explains why.

Every programmer fondly remembers the book that helped them get started. The goal of Beginning Rails is to become that book for you, today.

Table of Contents

  1. Introducing the Rails Framework
  2. Getting Started
  3. Getting Something Running
  4. Working with a Database: Active Record
  5. Advanced Active Record: Enhancing Your Models
  6. Action Pack:Working with the View and the Controller
  7. Improving Interaction with Ajax
  8. Sending and Receiving Mail
  9. Testing Your Application
  10. Extending Rails with Plugins
  11. Deploying Your Rails Applications
Read More Show Less

Product Details

  • ISBN-13: 9781590596869
  • Publisher: Apress
  • Publication date: 8/3/2007
  • Series: Expert's Voice Series
  • Edition number: 1
  • Pages: 361
  • Product dimensions: 0.81 (w) x 7.50 (h) x 9.25 (d)

Meet the Author

A bio is not available for this author.

Hampton Catlin was born in Jacksonville, Florida in 1982, on a sunny day with highs in the mid-80s and only a 20% chance of precipitation. He has been developing web applications since high school and fell in love with the Web all over again when he found the Rails framework. The creator of the Haml markup language and Sass (Haml for CSS), Hampton blogs at and is currently a partner at Unspace Interactive in Toronto.

Jeffrey Allan Hardy is a web developer, programmer, and occasional speaker with more than seven years of experience building large-scale web applications. He began working with Rails shortly after its first public release in 2004 and hasn't looked back. He is a partner at Unspace Interactive in Toronto, blogs at http://, and lives somewhere in the deep Canadian wilderness with his wife, his dog, and a cat.

Read More Show Less

Table of Contents

About the Authors     xv
About the Technical Reviewer     xvii
Acknowledgments     xix
Preface     xxi
Introduction     xxiii
Introducing the Rails Framework     1
The Rise and Rise of the Web Application     1
The Web Is Not Perfect     3
The Good Web Framework     3
Enter Rails     4
Rails Is Ruby     5
Rails Encourages Agility     6
Rails Is Opinionated Software     9
Rails Is Open Source     9
The MVC Pattern     10
The MVC Cycle     11
The Layers of MVC     12
The Libraries That Make Up Rails     15
Rails Is No Silver Bullet     15
Summary     16
Getting Started     17
An Overview of Rails Installation     17
Installing on Mac OS X 10.4 Tiger     19
Installing the Apple Developer Tools (Xcode)     20
Installing MySQL     20
Adding MySQL to Your Path     23
Installing Ruby     24
Installing RubyGems     26
Installing Rails     27
Automating Installation     27
Installing on Windows XP     28
Installing MySQL     29
Installing Ruby     30
Installing Rails     31
Installing on Linux     32
Installing MySQL     33
Installing Ruby     34
Installing RubyGems     35
Installing Rails     35
Creating Your First Rails Application     36
Starting the Built-In Web Server     37
Generating a Controller     39
Creating an Action     40
Creating a Template     40
Summary     43
Getting Something Running     45
An Overview of the Project     45
Creating the Events Application     46
Creating the Project Databases     48
Creating the Event Model     50
Creating a Database Table     51
Generating a Controller     54
Up and Running with Scaffolding     54
Adding More Fields     57
Adding Validations     59
Generating a Scaffold     60
Summary     63
Working with a Database: Active Record     65
Introducing Active Record: Object-Relational Mapping on Rails     66
What About SQL?     67
Active Record Conventions     68
Introducing the Console     69
Active Record Basics: CRUD     72
Creating New Records     72
Reading (Finding) Records     77
Updating Records     82
Deleting Records     83
When Good Models Go Bad     85
Summary     88
Advanced Active Record: Enhancing Your Models     89
Adding Methods     89
Using Associations     92
Declaring Associations     94
Creating One-to-One Associations     95
Creating One-to-Many Associations     99
Applying Association Options     105
Creating Many-to-Many Associations     107
Creating Rich Many-to-Many Associations     112
Building Conditions for Advanced Finding     115
Using a Conditions Hash     115
Using a SQL Fragment     116
Using an Array     117
Using Association Proxies     119
Applying Validations     120
Building Custom Validation Methods     121
Using Built-in Validations     122
Making Callbacks     125
Reviewing the Updated Models      127
Updating the User Model     128
Summary     132
Action Pack: Working with the View and the Controller     133
Action Pack Components     133
Action Controller     134
Action View     137
Embedded Ruby     138
Helpers     138
Routing     139
The Action Pack Request Cycle     140
A Controller Walk-Through     142
Setting Up Routes     142
Generating a Controller     146
Creating a Template     148
Working with Layouts     149
Creating a Registration Form     151
Using Form Helpers     153
Processing Request Parameters     156
Writing a Create Action     156
Rendering Responses     157
Redirecting     158
Displaying Error Messages in Templates     158
Adding the Edit Form     160
Staying Dry with Partials     161
Adding the Login and Logout Actions     165
Improving the Events Controller and Templates     171
Cleaning Up the Events Controller     171
Using Partials in the Events Templates      172
Adding Categories to the Events Form     173
Handling Categories in the Events Controller     175
Using Controller Filters     177
Requiring Authentication with Filters     178
Applying Filters to Controllers     180
Adding Finishing Touches     182
Using Action View Helpers     182
Escaping HTML in Templates     184
Formatting a Description Field     185
Adding Edit Controls     186
Adding Custom Helpers     188
Giving It Some Style     189
Summary     200
Improving Interaction with Ajax     201
Ajax and Rails     201
Prototype and Helpers     202
JavaScript Libraries     202
Using Ajax Helpers     203
Making Remote Calls with link_to_remote     204
Posting Forms Remotely with form_remote_tag     210
Polling for Changes with observe_field and observe_form     214
Using Helpers     217
Implementing Auto-Completion     217
Adding an In-Place Editor     219
Adding Visual Effects     222
Using RJS Templates     224
Implementing RJS in Templates      224
Implementing RJS in the Controller     227
Summary     228
Sending and Receiving Mail     229
Setting Up Action Mailer     229
Configuring Mail Server Settings     230
Configuring Application Settings     231
Sending Email     232
Handling Basic Email     234
Sending HTML Email     237
Adding Multiple Parts to Messages     239
Adding Attachments     240
Sending Incoming Email to a Rails Process     241
Summary     243
Testing Your Application     245
How Rails Handles Testing     246
Unit Testing Your Rails Application     247
Testing the Event Model     249
Testing Validations     255
Functional Testing Your Controllers     256
Testing the Events Controller     256
Creating a Test Helper     258
Running the Functional Test Suite     264
Integration Testing     267
Integration Testing the Events Application     268
Story-Based Testing     271
Running the Full Test Suite     275
Measuring Test Coverage with Rcov     276
Summary      278
Extending Rails with Plugins     279
Finding and Installing Plugins     279
Finding Plugins     280
Installing Plugins     281
Using a Plugin in Our Application     282
Modifying the Database     282
Modifying the Application to Use the Plugin     283
Creating Your Own Plugin     287
Making the Plugin Available to Applications     288
Creating the Plugin Module     289
Updating the Controller and Views     297
Summary     300
Deploying Your Rails Applications     301
Deploying with Capistrano     301
Capistrano Installation     302
Capistrano Recipes     305
Capistrano on the Deployment Server     307
Custom Capistrano Tasks     308
Setting Up Your Server Architecture     308
Monolithic Architecture     308
Proxy-Cluster Server: The New Kid on the Block     309
Becoming an Instant Deployment Expert     311
Summary     312
Ruby, a Programmer's Best Friend     315
Instant Interaction     315
Ruby Types     316
Strings      316
Numbers     318
Symbols     318
Arrays and Hashes     319
Language Basics     320
Variables     320
Operators     322
Blocks and Iterators     322
Control Structures     323
Methods     325
Classes and Objects     326
Objects     326
Classes     327
Ruby Documentation     330
Databases 101     331
Examining a Database Table     331
Working with Tables     332
Selecting Data     333
Inserting Data     335
Updating Data     335
Deleting Data     336
Understanding Relationships     337
SQL and Active Record     340
The Rails Community     341
Rails Mailing Lists     341
Rails IRC Channel     341
Rails Blogs and Podcast     342
Rails Wiki     343
Rails APIs     343
Rails Trac     344
Working with Rails Directory     344
Index     345
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)