Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Agile Web Development with Rails, 3rd Edition pptx
Nội dung xem thử
Mô tả chi tiết
Prepared exclusively for Maxim Filatov
Important Information
About Rails Versions
This book is written for Rails 2. As this printing of the book is going to press,
the current generally available Gem version of Rails is 2.2.2. The code in this
book has been tested against this version.
This book started life with the same text as the Second Edition, which covered Rails 1.2.6. Pages containing this original text have a gray heading and
footer. As we migrate content to Rails 2, you’ll find the header color changes
to red.
The Rails core team is continuing to work on Rails 2. From time to time, new
releases may introduce incompatibilities for applications written for prior
versions of Rails. In order to experiment with these changes, the Rails developers are making the changes available via Edge Rails (discussed starting
on page 268). These changes won’t affect you unless you explicitly install
this experimental code—you won’t find yourself running it unless you override Gem defaults or deliberately choose to use Edge Rails. However, if you do
decide to run this experimental Rails code, you’ll find that some stuff in this
book (and some stuff in your existing Rails applications) may no longer run.
To determine the version of Rails that you are running, you can issue rails -v
at a command prompt.
Sam, Dave, and David
Prepared exclusively for Maxim Filatov
Agile Web Development with Rails
Third Edition
Sam Ruby
Dave Thomas
David Heinemeier Hansson
with Leon Breedt
Mike Clark
James Duncan Davidson
Justin Gehtland
Andreas Schwarz
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
Prepared exclusively for Maxim Filatov
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital
letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers,
LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no
responsibility for errors or omissions, or for damages that may result from the use of information
(including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better
software and have more fun. For more information, as well as the latest Pragmatic titles, please
visit us at
http://www.pragprog.com
Copyright © 2009 The Pragmatic Programmers LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any
form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the
prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-16-6
ISBN-13: 978-1-9343561-6-6
Printed on acid-free paper.
B1.9 printing, January 7, 2009
Version: 2009-1-7
Prepared exclusively for Maxim Filatov
Contents
Preface to the Second Edition 12
Preface to the Third Edition 14
1 Introduction 15
1.1 Rails Is Agile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2 Finding Your Way Around . . . . . . . . . . . . . . . . . . . . . 18
1.3 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Part I—Getting Started 22
2 The Architecture of Rails Applications 23
2.1 Models, Views, and Controllers . . . . . . . . . . . . . . . . . . 23
2.2 Active Record: Rails Model Support . . . . . . . . . . . . . . . . 26
2.3 Action Pack: The View and Controller . . . . . . . . . . . . . . . 30
3 Installing Rails 32
3.1 Your Shopping List . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2 Installing on Windows . . . . . . . . . . . . . . . . . . . . . . . . 32
3.3 Installing on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . 34
3.4 Installing on Linux . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.5 Choosing a Rails Version . . . . . . . . . . . . . . . . . . . . . . 36
3.6 Development Environments . . . . . . . . . . . . . . . . . . . . 37
3.7 Rails and Databases . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.8 Keeping Up-to-Date . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.9 Rails and ISPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4 Instant Gratification 44
4.1 Creating a New Application . . . . . . . . . . . . . . . . . . . . . 44
4.2 Hello, Rails! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.3 Linking Pages Together . . . . . . . . . . . . . . . . . . . . . . . 57
4.4 What We Just Did . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Prepared exclusively for Maxim Filatov
CONTENTS 6
Part II—Building an Application 62
5 The Depot Application 63
5.1 Incremental Development . . . . . . . . . . . . . . . . . . . . . . 63
5.2 What Depot Does . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.3 Let’s Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6 Task A: Product Maintenance 69
6.1 Iteration A1: Get Something Running . . . . . . . . . . . . . . . 69
6.2 Create the Products Model and Maintenance Application . . . 75
6.3 Iteration A2: Add a Missing Column . . . . . . . . . . . . . . . 79
6.4 Iteration A3: Validate! . . . . . . . . . . . . . . . . . . . . . . . . 84
6.5 Iteration A4: Prettier Listings . . . . . . . . . . . . . . . . . . . . 89
7 Task B: Catalog Display 96
7.1 Iteration B1: Create the Catalog Listing . . . . . . . . . . . . . 96
7.2 Iteration B2: Add a Page Layout . . . . . . . . . . . . . . . . . . 100
7.3 Iteration B3: Use a Helper to Format the Price . . . . . . . . . 102
7.4 Iteration B4: Linking to the Cart . . . . . . . . . . . . . . . . . . 103
8 Task C: Cart Creation 107
8.1 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
8.2 Iteration C1: Creating a Cart . . . . . . . . . . . . . . . . . . . . 111
8.3 Iteration C2: A Smarter Cart . . . . . . . . . . . . . . . . . . . . 114
8.4 Iteration C3: Handling Errors . . . . . . . . . . . . . . . . . . . 117
8.5 Iteration C4: Finishing the Cart . . . . . . . . . . . . . . . . . . 122
9 Task D: Add a Dash of AJAX 127
9.1 Iteration D1: Moving the Cart . . . . . . . . . . . . . . . . . . . 128
9.2 Iteration D2: An AJAX-Based Cart . . . . . . . . . . . . . . . . 133
9.3 Iteration D3: Highlighting Changes . . . . . . . . . . . . . . . . 136
9.4 Iteration D4: Hide an Empty Cart . . . . . . . . . . . . . . . . . 139
9.5 Iteration D5: Degrading If Javascript Is Disabled . . . . . . . . 142
9.6 What We Just Did . . . . . . . . . . . . . . . . . . . . . . . . . . 143
10 Task E: Check Out! 145
10.1 Iteration E1: Capturing an Order . . . . . . . . . . . . . . . . . 145
11 Task F: Administration 161
11.1 Iteration F1: Adding Users . . . . . . . . . . . . . . . . . . . . . 161
11.2 Iteration F2: Logging In . . . . . . . . . . . . . . . . . . . . . . . 171
11.3 Iteration F3: Limiting Access . . . . . . . . . . . . . . . . . . . . 174
11.4 Iteration F4: A Sidebar, More Administration . . . . . . . . . . 177
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
CONTENTS 7
12 Task G: One Last Wafer-Thin Change 184
12.1 Generating the XML Feed . . . . . . . . . . . . . . . . . . . . . . 184
12.2 Finishing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
13 Task I: Internationalization 196
13.1 Iteration I1: Enabling Translation . . . . . . . . . . . . . . . . . 196
13.2 Iteration I2: Strategies for content . . . . . . . . . . . . . . . . . 211
14 Task T: Testing 214
14.1 Tests Baked Right In . . . . . . . . . . . . . . . . . . . . . . . . 214
14.2 Unit Testing of Models . . . . . . . . . . . . . . . . . . . . . . . . 215
14.3 Functional Testing of Controllers . . . . . . . . . . . . . . . . . 227
14.4 Integration Testing of Applications . . . . . . . . . . . . . . . . 244
14.5 Performance Testing . . . . . . . . . . . . . . . . . . . . . . . . . 253
14.6 Using Mock Objects . . . . . . . . . . . . . . . . . . . . . . . . . 257
Part III—The Rails Framework 260
15 Rails in Depth 261
15.1 So, Where’s Rails? . . . . . . . . . . . . . . . . . . . . . . . . . . 261
15.2 Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . 261
15.3 Rails Configuration . . . . . . . . . . . . . . . . . . . . . . . . . 268
15.4 Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . 272
15.5 Logging in Rails . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
15.6 Debugging Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
15.7 What’s Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
16 Active Support 280
16.1 Generally Available Extensions . . . . . . . . . . . . . . . . . . 280
16.2 Enumerations and Arrays . . . . . . . . . . . . . . . . . . . . . 281
16.3 Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.4 String Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.5 Extensions to Numbers . . . . . . . . . . . . . . . . . . . . . . . 286
16.6 Time and Date Extensions . . . . . . . . . . . . . . . . . . . . . 287
16.7 An Extension to Ruby Symbols . . . . . . . . . . . . . . . . . . 289
16.8 with_options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
16.9 Unicode Support . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
17 Migrations 296
17.1 Creating and Running Migrations . . . . . . . . . . . . . . . . . 298
17.2 Anatomy of a Migration . . . . . . . . . . . . . . . . . . . . . . . 300
17.3 Managing Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
17.4 Data Migrations . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
CONTENTS 8
17.5 Advanced Migrations . . . . . . . . . . . . . . . . . . . . . . . . 312
17.6 When Migrations Go Bad . . . . . . . . . . . . . . . . . . . . . . 315
17.7 Schema Manipulation Outside Migrations . . . . . . . . . . . . 316
17.8 Managing Migrations . . . . . . . . . . . . . . . . . . . . . . . . 317
18 Active Record: The Basics 319
18.1 Tables and Classes . . . . . . . . . . . . . . . . . . . . . . . . . 320
18.2 Columns and Attributes . . . . . . . . . . . . . . . . . . . . . . 320
18.3 Primary Keys and IDs . . . . . . . . . . . . . . . . . . . . . . . . 324
18.4 Connecting to the Database . . . . . . . . . . . . . . . . . . . . 326
18.5 CRUD—Create, Read, Update, Delete . . . . . . . . . . . . . . . 331
18.6 Aggregation and Structured Data . . . . . . . . . . . . . . . . . 350
18.7 Miscellany . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
19 Active Record: Relationships between Tables 361
19.1 Creating Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . 362
19.2 Specifying Relationships in Models . . . . . . . . . . . . . . . . 364
19.3 belongs_to and has_xxx Declarations . . . . . . . . . . . . . . . 366
19.4 Joining to Multiple Tables . . . . . . . . . . . . . . . . . . . . . 381
19.5 Self-referential Joins . . . . . . . . . . . . . . . . . . . . . . . . . 391
19.6 Acts As . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
19.7 When Things Get Saved . . . . . . . . . . . . . . . . . . . . . . . 396
19.8 Preloading Child Rows . . . . . . . . . . . . . . . . . . . . . . . 398
19.9 Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
20 Active Record: Object Life Cycle 401
20.1 Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
20.2 Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
20.3 Advanced Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 419
20.4 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
21 Action Controller: Routing and URLs 431
21.1 The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
21.2 Routing Requests . . . . . . . . . . . . . . . . . . . . . . . . . . 432
21.3 Resource-Based Routing . . . . . . . . . . . . . . . . . . . . . . 448
21.4 Testing Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
22 Action Controller and Rails 467
22.1 Action Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
22.2 Cookies and Sessions . . . . . . . . . . . . . . . . . . . . . . . . 479
22.3 Flash—Communicating between Actions . . . . . . . . . . . . . 489
22.4 Filters and Verification . . . . . . . . . . . . . . . . . . . . . . . 491
22.5 Caching, Part One . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
CONTENTS 9
22.6 The Problem with GET Requests . . . . . . . . . . . . . . . . . . 508
23 Action View 512
23.1 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
23.2 Using Helpers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
23.3 Helpers for Formatting, Linking, and Pagination . . . . . . . . 520
23.4 How Forms Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
23.5 Forms That Wrap Model Objects . . . . . . . . . . . . . . . . . . 529
23.6 Custom Form Builders . . . . . . . . . . . . . . . . . . . . . . . 541
23.7 Working with Nonmodel Fields . . . . . . . . . . . . . . . . . . . 546
23.8 Uploading Files to Rails Applications . . . . . . . . . . . . . . . 549
23.9 Layouts and Components . . . . . . . . . . . . . . . . . . . . . . 553
23.10 Caching, Part Two . . . . . . . . . . . . . . . . . . . . . . . . . . 560
23.11 Adding New Templating Systems . . . . . . . . . . . . . . . . . 565
24 The Web, V2.0 568
24.1 Prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
24.2 Script.aculo.us . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
24.3 RJS Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
24.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
25 Action Mailer 614
25.1 Sending E-mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
25.2 Receiving E-mail . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
25.3 Testing E-mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
26 Active Resources 630
26.1 Alternatives to ActiveResource . . . . . . . . . . . . . . . . . . . 630
26.2 Show me the Code! . . . . . . . . . . . . . . . . . . . . . . . . . 633
26.3 Relationships and Collections . . . . . . . . . . . . . . . . . . . 636
26.4 Pulling it all together . . . . . . . . . . . . . . . . . . . . . . . . 638
Part IV—Secure and Deploy Your Application 641
27 Securing Your Rails Application 642
27.1 SQL Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642
27.2 Creating Records Directly from Form Parameters . . . . . . . 644
27.3 Don’t Trust ID Parameters . . . . . . . . . . . . . . . . . . . . . 646
27.4 Don’t Expose Controller Methods . . . . . . . . . . . . . . . . . 647
27.5 Cross-Site Scripting (CSS/XSS) . . . . . . . . . . . . . . . . . . 648
27.6 Avoid Session Fixation Attacks . . . . . . . . . . . . . . . . . . 650
27.7 File Uploads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
27.8 Don’t Store Sensitive Information in the Clear . . . . . . . . . 652
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
CONTENTS 10
27.9 Use SSL to Transmit Sensitive Information . . . . . . . . . . . 653
27.10 Don’t Cache Authenticated Pages . . . . . . . . . . . . . . . . . 654
27.11 Knowing That It Works . . . . . . . . . . . . . . . . . . . . . . . 654
28 Deployment and Production 656
28.1 Starting Early . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
28.2 How a Production Server Works . . . . . . . . . . . . . . . . . . 657
28.3 Installing Passenger . . . . . . . . . . . . . . . . . . . . . . . . . 660
28.4 Worry free Deployment with Capistrano . . . . . . . . . . . . . 662
28.5 Checking Up on a Deployed Application . . . . . . . . . . . . . 666
28.6 Production Application Chores . . . . . . . . . . . . . . . . . . . 667
28.7 Moving On to Launch and Beyond . . . . . . . . . . . . . . . . 669
Part V—Appendices 671
A Introduction to Ruby 672
A.1 Ruby Is an Object-Oriented Language . . . . . . . . . . . . . . 672
A.2 Ruby Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
A.3 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
A.4 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676
A.5 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
A.6 Arrays and Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . 679
A.7 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 680
A.8 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 681
A.9 Blocks and Iterators . . . . . . . . . . . . . . . . . . . . . . . . . 681
A.10 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682
A.11 Marshaling Objects . . . . . . . . . . . . . . . . . . . . . . . . . 683
A.12 Interactive Ruby . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
A.13 Ruby Idioms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
A.14 RDoc Documentation . . . . . . . . . . . . . . . . . . . . . . . . 685
B Configuration Parameters 686
B.1 Top-Level Configuration . . . . . . . . . . . . . . . . . . . . . . . 686
B.2 Active Record Configuration . . . . . . . . . . . . . . . . . . . . 688
B.3 Action Controller Configuration . . . . . . . . . . . . . . . . . . 691
B.4 Action View Configuration . . . . . . . . . . . . . . . . . . . . . 692
B.5 Action Mailer Configuration . . . . . . . . . . . . . . . . . . . . 693
B.6 Test Case Configuration . . . . . . . . . . . . . . . . . . . . . . . 694
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
CONTENTS 11
C Source Code 695
C.1 The Full Depot Application . . . . . . . . . . . . . . . . . . . . . 695
D Resources 724
D.1 Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . 724
Index 726
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
Tous les jours, à tous les points de vue, je vais de mieux en
mieux.
Émile Coué
Preface to the Second Edition
It has been 18 months since I announced the first edition of this book. It
was clear before the book came out that Rails would be big, but I don’t think
anyone back then realized just how significant this framework would turn out
to be.
In the year that followed, Rails went from strength to strength. It was used
as the basis for any number of new, exciting web sites. Just as significantly,
large corporations (many of them household names) started to use Rails for
both inward- and outward-facing applications. Rails gained critical acclaim,
too. David Heinemeier Hansson, the creator of Rails, was named Hacker of the
Year at OSCON. Rails won a Jolt Award as best web development tool, and the
first edition of this book received a Jolt Award as best technical book.
But the Rails core team didn’t just sit still, soaking up the praise. Instead,
they’ve been heads-down adding new features and facilities. Rails 1.0, which
came out some months after the first edition hit the streets, added features
such as database migration support, as well as updated AJAX integration.
Rails 1.1, released in the spring of 2006, was a blockbuster, with more than
500 changes since the previous release. Many of these changes are deeply
significant. For example, RJS templates change the way that developers write
AJAX-enabled applications, and the integration testing framework changes the
way these applications can be tested. A lot of work has gone into extending and
enhancing Active Record, which now includes polymorphic associations, join
models, better caching, and a whole lot more.
The time had come to update the book to reflect all this goodness. And, as I
started making the changes, I realized that something else had changed. In the
time since the first book was released, we’d all gained a lot more experience
of just how to write a Rails application. Some stuff that seemed like a great
idea didn’t work so well in practice, and other features that initially seemed
peripheral turned out to be significant. And those new practices meant that
the changes to the book went far deeper than I’d expected. I was no longer
doing a cosmetic sweep through the text, adding a couple of new APIs. Instead,
I found myself rewriting the content. Some chapters from the original have
been removed, and new chapters have been added. Many of the rest have been
Prepared exclusively for Maxim Filatov
PREFACE TO THE SECOND EDITION 13
completely rewritten. So, it became clear that we were looking at a second
edition—basically a new book.
It seems strange to be releasing a second edition at a time when the first
edition is still among the best-selling programming books in the world. But
Rails has changed, and we need to change this book with it.
Enjoy!
Dave Thomas
October 2006
Report erratum
this copy is (B1.9 printing, January 7, 2009) Prepared exclusively for Maxim Filatov
Preface to the Third Edition
When Dave asked me to join as a co-author of the third edition of this book,
I was thrilled. After all, it was from the first printing of the first edition of
this book that I had learned Rails. Dave and I also have much in common.
While he prefers Emacs and Mac OS X and my preferences tend towards VIM
and Ubuntu, we both share a love for the command line and getting our fingers dirty with code; starting with tangible examples before diving into heavy
theory.
Since the time the first edition was published (and, in fact, since the second
edition) much has changed. Rails is now either pre-installed or packaged for
easy installation on all major development platforms. Rails itself has evolved,
and a number of features that were used in previous examples have been
initially deprecated and subsequently removed. New features have been added,
and much experience has been obtained as to what the best practices are for
using rails.
As such, this book needs to adapt. Once again.
Sam Ruby
January 2009
Prepared exclusively for Maxim Filatov
Chapter 1
Introduction
Ruby on Rails is a framework that makes it easier to develop, deploy, and
maintain web applications. During the months that followed its initial release,
Rails went from being an unknown toy to being a worldwide phenomenon. It
has won awards and, more importantly, it has become the framework of choice
for the implementation of a wide range of so-called Web 2.0 applications. It
isn’t just trendy among hard-core hackers: many multinational companies are
using Rails to create their web applications.
Why is that? There seem to be many reasons.
First, there seemed to be a large number of developers who were frustrated
with the technologies they were using to create web applications. It didn’t seem
to matter whether they were using Java, PHP, or .NET—there was a growing
sense that their job was just too damn hard. And then, suddenly, along came
Rails, and Rails is easier.
But easy on its own doesn’t cut it. We’re talking about professional developers
writing real-world web sites. They wanted to feel that the applications they
were developing would stand the test of time—that they were designed and
implemented using modern, professional techniques. So these developers dug
into Rails and discovered it wasn’t just a tool for hacking out sites.
For example, all Rails applications are implemented using the Model-ViewController (MVC) architecture. Java developers are used to frameworks such
as Tapestry and Struts, which are based on MVC. But Rails takes MVC further:
when you develop in Rails, there’s a place for each piece of code, and all the
pieces of your application interact in a standard way. It’s as if you start out
with the skeleton of an application already prepared.
Professional programmers write tests. And again, Rails delivers. All Rails applications have testing support baked right in. As you add functionality to the
Prepared exclusively for Maxim Filatov