| Acknowledgments | | xi | |
| Introduction | | xix | |
| | 1 | |
| Installing Ruby and Rails |
| | 1 | |
| Install Ruby and Rails on Windows |
| | 1 | |
| Install Ruby and Rails in Mac OS X |
| | 2 | |
| Install Ruby and Rails in Linux and Unix |
| | 2 | |
| | 3 | |
| Creating a First Web Application |
| | 3 | |
| Getting Started with Ruby |
| | 7 | |
| Checking the Ruby Documentation |
| | 9 | |
| Working with Numbers in Ruby |
| | 10 | |
| Working with Strings in Ruby |
| | 11 | |
| Storing Data in Variables |
| | 13 | |
| | 15 | |
| Interpolating Variables in Double-Quoted Strings |
| | 15 | |
| Reading Text on the Command Line |
| | 16 | |
| | 18 | |
| | 18 | |
| Handling Operator Precedence |
| | 21 | |
| | 21 | |
| | 24 | |
| | 27 | |
| | 29 | |
| | 31 | |
| | 32 | |
| Conditionals, Loops, Methods, and Blocks |
| | 33 | |
| It's All about Making Choices: the If Statement |
| | 33 | |
| Using else Clauses in if Statements |
| | 34 | |
| Using elsif Clauses in if Statements |
| | 35 | |
| Using the unless Statement |
| | 37 | |
| Using if and unless as Modifiers |
| | 38 | |
| | 39 | |
| | 41 | |
| | 42 | |
| | 42 | |
| Using while and until as Modifiers |
| | 43 | |
| | 44 | |
| | 45 | |
| Working with break, redo, and next in Loops |
| | 48 | |
| Using the retry Statement |
| | 50 | |
| Creating and Calling a Method |
| | 51 | |
| Passing Arguments to a Method |
| | 52 | |
| Passing a Variable Number of Arguments |
| | 53 | |
| Returning a Value from a Method |
| | 54 | |
| Returning Multiples Values from a Method |
| | 56 | |
| | 57 | |
| | 58 | |
| | 60 | |
| Using Begin and End Blocks |
| | 61 | |
| | 61 | |
| | 62 | |
| | 63 | |
| | 63 | |
| | 64 | |
| | 66 | |
| Using a Constructor to Configure Objects |
| | 67 | |
| Understanding Ruby Attributes |
| | 68 | |
| Creating Readable Attributes |
| | 68 | |
| Creating Writable Attributes |
| | 69 | |
| Creating Readable and Writable Attributes |
| | 71 | |
| Basing One Class on Another |
| | 72 | |
| Understanding Ruby's Object Access |
| | 75 | |
| | 76 | |
| | 78 | |
| | 79 | |
| | 80 | |
| | 82 | |
| | 83 | |
| | 85 | |
| | 87 | |
| | 87 | |
| | 89 | |
| | 89 | |
| Creating the Application Framework |
| | 90 | |
| | 93 | |
| | 94 | |
| Using the Rails Documentation |
| | 94 | |
| | 95 | |
| | 96 | |
| | 97 | |
| Introducing Model-View-Controller Architecture |
| | 100 | |
| | 101 | |
| | 101 | |
| | 102 | |
| Giving the View Something to Do |
| | 102 | |
| Mixing Ruby Code and HTML Inside the View |
| | 105 | |
| Passing Data from an Action to a View |
| | 108 | |
| | 111 | |
| | 113 | |
| Selecting Which View to Render |
| | 116 | |
| | 118 | |
| Linking to Another Action |
| | 118 | |
| | 120 | |
| | 121 | |
| Building Simple Rails Applications |
| | 123 | |
| Accessing Data the User Provides |
| | 123 | |
| Reading Data from Text Fields |
| | 123 | |
| Reading Data from Checkboxes |
| | 127 | |
| Reading Data from Radio Buttons |
| | 130 | |
| Reading Data from Select Controls |
| | 132 | |
| Using Rails Shortcuts for HTML Controls |
| | 137 | |
| | 143 | |
| | 145 | |
| Initializing Data in Controls |
| | 151 | |
| | 153 | |
| | 157 | |
| | 157 | |
| | 159 | |
| | 159 | |
| Creating a Data-Aware Rails Application |
| | 162 | |
| | 162 | |
| Configuring Database Access |
| | 165 | |
| Creating the Controller and Model |
| | 167 | |
| | 168 | |
| | 168 | |
| Running the store Application |
| | 169 | |
| Adding a Record to the store Application |
| | 171 | |
| | 175 | |
| | 176 | |
| | 177 | |
| | 178 | |
| | 180 | |
| | 182 | |
| | 187 | |
| | 189 | |
| | 189 | |
| | 191 | |
| Displaying Items to the Customer |
| | 191 | |
| Getting the Items for Sale |
| | 192 | |
| Showing the Items for Sale |
| | 194 | |
| | 197 | |
| Designing the Shopping Cart |
| | 197 | |
| Creating the purchases Table |
| | 199 | |
| Creating the Purchase Model |
| | 200 | |
| | 203 | |
| Storing the Cart in a Session |
| | 205 | |
| | 206 | |
| | 209 | |
| Combining Purchases in the Cart |
| | 213 | |
| | 216 | |
| Letting the User View the Cart Anytime |
| | 219 | |
| | 221 | |
| | 222 | |
| | 223 | |
| Validating the Presence of Data |
| | 223 | |
| Validating if Data Is Numeric |
| | 226 | |
| Validating if Data Is Unique |
| | 229 | |
| Creating the Validator Application |
| | 231 | |
| Validating the Format of Data |
| | 233 | |
| Validating against Inclusion in a List |
| | 235 | |
| Validating That the User Clicked a Checkbox |
| | 238 | |
| Validating Confirmation of Passwords |
| | 240 | |
| Validating Length of Text |
| | 243 | |
| Writing Your Own Validate Method |
| | 246 | |
| | 248 | |
| Using Equality Assertions |
| | 253 | |
| | 254 | |
| | 255 | |
| | 256 | |
| | 259 | |
| | 259 | |
| Controlling the Action with the Action Controller |
| | 261 | |
| | 261 | |
| | 266 | |
| | 267 | |
| | 270 | |
| | 273 | |
| | 278 | |
| | 285 | |
| | 290 | |
| | 292 | |
| | 293 | |
| | 294 | |
| Getting the Big Picture with Views |
| | 295 | |
| | 295 | |
| | 300 | |
| | 303 | |
| | 309 | |
| | 315 | |
| Passing Data to Partial Templates |
| | 317 | |
| | 320 | |
| | 320 | |
| | 321 | |
| | 321 | |
| Getting Access to Ajax Data |
| | 325 | |
| | 329 | |
| Using HTML Controls and Ajax |
| | 334 | |
| | 338 | |
| Performing Visual Effects |
| | 342 | |
| | 344 | |
| | 345 | |
| Appendix A: Answers to Exercises | | 347 | |
| Index | | 363 | |