I came to rails knowing very little about ruby and even less about rails. This book got me started on the right foot. At the end I was able to understand how rails works, although I wasn't able to write any real programs on my own. This book assumes that you know nothing about Ruby or Rails. It's written in a clear, concise and entertaining style, and gave me a good idea how the whole rails framework functions. Agile Web Development with Rails, Third Edition is one of the more popular guides that I'm reading now. It's also a good beginner's book but it might be too difficult for complete newbies. I think I'd have much more difficulty understanding it if I hadn't read Simply Rails.
Author(s): Patrick Lenz
Edition: 2
Publisher: SitePoint
Year: 2008
Language: English
Pages: 500
Simply Rails 2......Page 1
Table of Contents......Page 10
Who Should Read This Book?......Page 20
What’s in This Book?......Page 21
The Code Archive......Page 23
Your Feedback......Page 24
Code Samples......Page 25
Acknowledgments......Page 26
Introducing Ruby on Rails......Page 28
History......Page 31
Convention Over Configuration......Page 32
Don’t Repeat Yourself......Page 34
Agile Development......Page 35
Building the Example Web Application......Page 36
What Is Digg?......Page 37
Features of the Example Application......Page 39
Summary......Page 41
Getting Started......Page 42
What Does All This Cost?......Page 43
Installing on Windows......Page 44
Installing on Mac OS X......Page 46
Installing Xcode......Page 47
Introducing the Command Line......Page 48
Setting the Path......Page 50
Staying Organized......Page 51
Installing Ruby on a Mac......Page 52
Installing RubyGems on a Mac......Page 53
Installing Rails on a Mac......Page 55
Installing SQLite on a Mac......Page 56
Installing the SQLite Database Interface for Ruby......Page 57
Installing on Linux......Page 58
Prerequisites......Page 59
Installing Ruby on Linux......Page 60
Installing RubyGems on Linux......Page 62
Installing Rails on Linux......Page 64
Installing SQLite on Linux......Page 65
Installing the SQLite Database Interface for Ruby......Page 66
One Directory Structure to Rule Them All......Page 67
Creating the Standard Directory Structure......Page 68
Starting Our Application......Page 70
Which Text Editor?......Page 73
Windows Text Editors......Page 74
Mac OS X Text Editors......Page 75
Summary......Page 77
Ruby Is a Scripting Language......Page 80
The Great Performance Debate......Page 81
Ruby Is an Object Oriented Language......Page 82
The Interactive Ruby Shell (irb)......Page 86
Literal Objects......Page 87
Variables and Constants......Page 88
Punctuation in Ruby......Page 89
Use of Parentheses......Page 90
Method Notation......Page 91
Object Oriented Programming in Ruby......Page 92
Object-level Functionality......Page 93
Instance Methods......Page 94
Accessor Methods......Page 95
Class-level Functionality......Page 97
Inheritance......Page 99
Return Values......Page 100
Standard Output......Page 101
Arrays......Page 102
Hashes......Page 104
Strings......Page 106
Numerics......Page 107
nil......Page 109
Control Structures......Page 110
The if Construct......Page 112
The unless Construct......Page 113
while and until Loops......Page 115
for Loops......Page 116
Blocks......Page 117
Summary......Page 119
Three Environments......Page 120
The Database Configuration File......Page 122
The Model-View-Controller Architecture......Page 123
MVC in Theory......Page 124
MVC the Rails Way......Page 125
Database Abstraction......Page 127
Database Tables......Page 128
Using the Rails Console......Page 129
Saving an Object......Page 130
Defining Relationships Between Objects......Page 131
The ActionPack Module......Page 132
ActionController (the Controller)......Page 133
ActionView (the View)......Page 134
The REST......Page 137
In Theory......Page 138
REST and the Web......Page 139
Code Generation......Page 140
Testing......Page 142
Integration Testing......Page 143
Summary......Page 144
The Model Generator......Page 146
Running the generate Script......Page 147
Understanding the Output......Page 149
Understanding YAML......Page 151
Modifying the Schema Using Migrations......Page 152
Creating a Skeleton Migration File......Page 153
Creating the stories Table......Page 154
Using rake to Migrate Our Data......Page 156
Creating Records......Page 160
Retrieving Records......Page 162
Updating Records......Page 164
Where’s the SQL?......Page 165
Generating a Controller......Page 166
Running the generate Script......Page 167
Understanding the Output......Page 168
Starting Our Application … Again......Page 170
Generating Views with Scaffolding......Page 172
Creating Dynamic Pages......Page 175
Passing Data Back and Forth......Page 177
Pulling in a Model......Page 178
Summary......Page 180
Calling upon Our Trusty Helpers......Page 182
Enabling Story Submission......Page 183
Introducing the form_for Helper......Page 184
Creating the Template......Page 185
Modifying the Controller......Page 188
Resources in Rails......Page 189
Analyzing the HTML......Page 191
Saving Data to the Database......Page 193
Redirecting with URL helpers......Page 194
Creating a Layout......Page 195
Establishing Structure......Page 196
Adding Some Style......Page 197
Adding to the Flash......Page 199
Retrieving Data from the Flash......Page 200
Applying Validations......Page 201
Tweaking the Redirection Logic......Page 202
Improving the User Experience......Page 203
Testing the Form......Page 205
Analyzing the Skeleton File......Page 207
Writing a Unit Test......Page 208
Running a Unit Test......Page 210
Analyzing the Skeleton File......Page 212
Writing a Functional Test......Page 213
Writing More Functional Tests......Page 215
Running the Complete Test Suite......Page 219
Revisiting the Logs......Page 220
Summary......Page 222
Generating a Vote Model......Page 224
Examining the Vote Migration......Page 225
Introducing Relationships......Page 227
Introducing the has_many Clause......Page 228
Introducing the belongs_to Clause......Page 231
How’s Our Schema Looking?......Page 232
Determining Where a Story Lives......Page 233
Displaying Our Stories......Page 234
Improving the Story Randomizer......Page 235
Implementing Clean URLs......Page 236
Converting from Strings to Numbers......Page 237
Investigating Link Generation......Page 238
Introducing Ajax......Page 240
Remote Scripting with Prototype......Page 241
Adding Visual Effects with script.aculo.us......Page 242
Controlling Where the Votes Go......Page 244
Including the JavaScript Libraries......Page 247
Giving Stories a Shove......Page 249
Styling the Scoreboard......Page 250
Storing the Votes......Page 251
Introducing RJS Templates......Page 252
Ensuring Graceful Degradation......Page 255
Adding Voting History......Page 258
Creating the Partial......Page 259
Styling the Voting History......Page 260
Tweaking the Voting History......Page 263
Preparing the Fixtures......Page 265
Testing a Story’s Relationship to a Vote......Page 266
Testing a Vote’s Relationship to a Story......Page 267
Testing the Voting History Order......Page 268
Testing the Controller......Page 269
Testing Page Rendering......Page 270
Testing Vote Storage......Page 271
Testing Ajax Voting......Page 272
Testing Regular HTTP Voting......Page 273
Summary......Page 274
Introducing Sessions and Cookies......Page 276
What’s a Cookie?......Page 277
What’s a Session?......Page 279
Sessions in Rails......Page 280
Generating a User Model......Page 281
Adding Relationships for the User Class......Page 283
Creating a User......Page 285
Creating the Controller......Page 286
Creating the View......Page 288
Adding Functionality to the Controller......Page 290
After Filters......Page 293
A Word on Filter Methods......Page 294
Retrieving the Current User......Page 296
Displaying the Name of the Current User......Page 298
Allowing Users to Log Out......Page 300
Adding a Navigation Menu......Page 302
Protecting the Form......Page 303
Abstracting Code Using helper_method......Page 304
Requiring Users to Log In......Page 305
Introducing Filter Conditions......Page 306
Redirecting the User......Page 307
Storing the Submitter......Page 308
Displaying the Submitter......Page 309
Preparing the Fixtures......Page 311
Testing a Story’s Relationship to a User......Page 313
Testing a User’s Relationship to a Vote......Page 314
Running the Unit Tests......Page 315
Testing the Display of the Login Form......Page 316
Testing a Successful Login......Page 317
Testing a Failed Login......Page 318
Testing a Logout......Page 319
Testing the Display of the Story Submitter......Page 320
Testing Display of the Username......Page 321
Testing Redirection After Logout......Page 323
Testing Story Submission......Page 324
Running the Full Test Suite......Page 325
Summary......Page 327
Promoting Popular Stories......Page 330
Introducing the Counter Cache......Page 331
Making Room for the Cache......Page 332
Updating the RJS Template......Page 334
Modifying the Controller......Page 335
Modifying the View......Page 336
Creating the Partial......Page 337
Styling the Front Page......Page 338
Setting the Default Page......Page 339
Implementing the Voting Bin......Page 340
Adding Custom Actions to RESTful Routes......Page 342
Abstracting Presentation Logic......Page 343
Introducing ActionView Helpers......Page 344
Writing an ActionView Helper......Page 345
Expanding the Navigation Menu......Page 346
Requiring a Login to Vote......Page 348
Auto-voting for Newly Submitted Stories......Page 350
Introducing Model Callbacks......Page 351
Adding a Callback......Page 352
Adding a Model Attribute......Page 353
Expanding the Submission Form......Page 354
Introducing the Join Model Relationship......Page 357
Introducing the has_many :through Association......Page 358
Adding Another Controller......Page 359
Creating the View......Page 360
Testing Additions to the Counter Cache......Page 363
Testing Deletions from the Counter Cache......Page 365
Testing the Creation of the Initial Vote......Page 366
Testing the Join Model Relationship......Page 367
Testing the Rendering of Templates......Page 368
Testing the Routing Configuration......Page 369
Testing Page Headings......Page 370
Testing the Navigation Menu......Page 371
Testing Restricted Functionality......Page 372
Testing the UsersController......Page 373
Running the Complete Test Suite......Page 374
Summary......Page 375
What Is a Plugin?......Page 378
Adding Tagging to Shovell......Page 380
What acts_as_taggable_on_steroids Does......Page 381
Installing the acts_as_taggable_on_steroids Plugin......Page 382
Creating a Migration for the Plugin......Page 383
Understanding Polymorphic Associations......Page 386
Making a Model Taggable......Page 387
Modifying the View......Page 390
Modifying the View......Page 391
Assigning Our First Tags......Page 392
Creating the Controller......Page 394
Displaying Tagged Stories......Page 396
Updating the Style Sheet......Page 397
Testing the Assignment of Tags......Page 399
Testing the Finding of a Story by Tag......Page 400
Testing the Submission of a New Story with Tags......Page 401
Testing the Display of the Story Submission Form......Page 402
Testing the Display of Stories by Tag......Page 403
Running the Test Suite ... Again!......Page 404
Summary......Page 405
Debugging, Testing, and Benchmarking......Page 406
Debugging within Templates......Page 407
Debugging using ruby-debug......Page 415
Meeting ruby-debug......Page 416
Installing ruby-debug......Page 417
Adding ruby-debug to Your Application......Page 418
Debugging an Application......Page 419
The ruby-debug Commands......Page 420
Moving Around in the Shell......Page 421
Discovering All the Fancy Tools in ruby-debug......Page 425
Setting Breakpoints Mid-execution......Page 428
TextMate Integration......Page 430
Using the Rails Logging Tool......Page 432
When to Use an Integration Test......Page 435
Creating Our First Integration Test......Page 436
Running an Integration Test......Page 438
Using Breakpoints in a Test......Page 439
Revisiting the Rails Console......Page 441
Benchmarking Your Application......Page 444
Taking Benchmarks from Log Files......Page 445
Manual Benchmarking......Page 448
Summary......Page 450
The Implications of “Production”......Page 452
Choosing a Production Environment......Page 454
Apache......Page 455
nginx......Page 456
The SCGI Protocol......Page 457
Mongrel......Page 458
Moving to the Production System......Page 459
Setting up Apache......Page 465
The ActiveRecord Store Session Container......Page 468
The MemCached Store Session Container......Page 470
Caching......Page 471
Capistrano......Page 472
Summary......Page 473
Index......Page 476