Tải bản đầy đủ

1935182277 {87299DF3} rails 3 in action bigg katz 2011 10 01

IN ACTION
Ryan Bigg
Yehuda Katz

MANNING


Rails 3 in Action



Rails 3 in Action
RYAN BIGG
YEHUDA KATZ

MANNING
SHELTER ISLAND


iv
For online information and ordering of this and other Manning books, please visit

www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 261
Shelter Island, NY 11964
Email: orders@manning.com

©2012 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.

Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.

Manning Publications Co.
20 Baldwin Road
PO Box 261
Shelter Island, NY 11964

Development editor:
Copyeditors:
Proofreader:
Typesetter:
Cover designer:

ISBN 978-1-935182-27-6
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 16 15 14 13 12 11


Cynthia Kane
Kevin Hobson, Linda Kern
Tiffany Taylor
Dottie Marsico
Marija Tudor


brief contents
1



Ruby on Rails, the framework 1

2



Testing saves your bacon

3



Developing a real Rails application

4



Oh CRUD!

5



Nested resources

6



Authentication and basic authorization

7



Basic access control

8



More authorization 164

9



File uploading 213

10



Tracking state

11



Tagging

12



Sending email 312

13



Designing an API

14



Deployment 385

15



Alternative authentication 412

16



Basic performance enhancements

17



Engines

18



Rack-based applications 516

23
44

83
99
136

243

286
347

468

v

434

117



contents
preface xv
acknowledgments xvii
about this book xx
about the authors xxiii
about the cover illustration xxiv

1

Ruby on Rails, the framework
1.1

What is Ruby on Rails? 2
Benefits

1.2

1

2

Common terms 3





Rails in the wild 4

Developing your first application 5
Installing Rails 5 Generating an application 6 Starting the
application 6 Scaffolding 7 Migrations 8 Viewing
and creating purchases 9 Validations 13 Showing off 14
Routing 15 Updating 16 Deleting 20














1.3

2

Summary

21

Testing saves your bacon
2.1
2.2

25



Writing your first test

Behavior-driven development
RSpec

2.4

23

Test- and behavior-driven development 24
Test-driven development 24
Why test?

2.3





29

Summary



Cucumber

42
vii

35

28

25



Saving bacon

27


viii

CONTENTS

3

Developing a real Rails application
3.1

Application setup

44

45

The application story 45 Version control 47 The Gemfile
and generators 50 Database configuration 53 Applying a
stylesheet 54






3.2



First steps 55
Creating projects 55 RESTful routing 60 Committing
changes 72 Setting a page title 72 Validations 76






3.3

4

Summary

Oh CRUD!
4.1

4.2



81

83

Viewing projects

83

Writing a feature
a project 86

84

Editing projects
The edit action

4.3

The Factory Girl

85

The update action

90





88
88



Deleting projects 91
Writing a feature 92 Adding a destroy action
for what isn’t there 93


4.4

5

Summary

Nested resources
5.1

Adding a link to

92



Looking

97

99

Creating tickets 99
Nested routing helpers 100 Creating a tickets controller 101
Defining a has_many association 103 Creating tickets within a
project 104 Finding tickets scoped by project 105 Ticket
validations 106






5.2

Viewing tickets
Listing tickets

5.3



108
110

Editing tickets



6

111

112

Adding the edit action

5.4
5.5

Culling tickets
113



Adding the update action

Deleting tickets 115
Summary 116

Authentication and basic authorization 117
6.1

What Devise does 118
Installing Devise

118

114


ix

CONTENTS

6.2
6.3

User signup 121
Confirmation link sign-in 122
Testing email

6.4
6.5

122

Confirming confirmation



Form sign-in 126
Linking tickets to users

123

128

Attributing tickets to users 129 We broke something! 131
Fixing the Viewing Tickets feature 132 Fixing the Editing
Tickets feature 133 Fixing the Deleting Tickets feature 134






6.6

7

Summary

135

Basic access control 136
7.1
7.2
7.3

Projects can be created only by admins 137
Adding the admin field to the users table 138
Restricting actions to admins only 138
Fixing three more broken scenarios 143 Hiding the New Project
link 144 Hiding the edit and delete links 146




7.4
7.5

Namespace routing 148
Namespace-based CRUD 151
Adding a namespace root 151 The index action
The new action 153 The create action 154


152



7.6
7.7

Creating admin users 155
Editing users 157
The show action

7.8

158



The edit and update actions

Deleting users 161
Ensuring you can’t delete yourself

7.9

8

Summary

162

163

More authorization
8.1
8.2
8.3

159

164

Restricting read access 165
Restricting by scope 168
Fixing what you broke 172
Fixing Editing Projects 173 Fixing the four failing
features 173 One more thing 176 Fixing Signing Up




8.4



Blocking access to tickets
Locking out the bad guys

183

183

178


x

CONTENTS

8.5

Restricting write access

185

Rewriting a feature 185 Blocking creation
CanCan? 188 Adding abilities 189

187





What is



8.6

Restricting update access
No updating for you!

8.7

191

190

Restricting delete access

Assigning permissions
Viewing projects 198

8.9
8.10

9

193

And the rest

206

213

Attaching a file

214

Attaching many files
Two more files 221

9.3

Hiding links based on

198



A feature featuring files 214
Using Paperclip 217

9.2



Seed data 209
Summary 212

File uploading
9.1

192

193

Enforcing destroy protection
permission 194

8.8

Authorizing editing





Enter stage right, Paperclip

216

220
Using nested attributes



Serving files through a controller

224

226

Protecting files 227 Showing your assets
assets 230 Privatizing assets 230


228



Public



9.4

Using JavaScript 231
JavaScript testing 232 Introducing jQuery 233 Adding
more files with JavaScript 234 Responding to an asynchronous
request 235 Sending parameters for an asynchronous
request 237








9.5

10

Summary

241

Tracking state 243
10.1

Leaving a comment

244

Where’s the ticket? 245 The comment form 247
The comment model 247 The comments controller 249




10.2

Changing a ticket’s state 252
Creating the State model 253 Selecting states 255
Callbacks 257 Seeding states 259 Fixing creating
comments 261







xi

CONTENTS

10.3

Tracking changes

263

Ch-ch-changes 263 Another c-c-callback 264 Displaying
changes 265 Show me the page 266 Automatic escaping
saves your bacon 267 Styling states 268










10.4

Managing states

269

Adding additional states

10.5

Locking down states

270



Defining a default state

273

278

Hiding a select box 278 Bestowing changing state
permissions 280 Hacking a form 282 Ignoring a
parameter 283




10.6

11

Summary

Tagging
11.1



285

286

Creating tags 287
Creating tags feature 287 Using text_field_tag 288
Showing tags 288 Defining the tags association 289
The Tag model 289 Displaying a ticket’s tags 290






11.2

Adding more tags

292

Adding tags through a comment
CommentsController spec 294

11.3

Tag restriction

292

Fixing the



295

Testing tag restriction 295
Tags are allowed, for some 296

11.4

Deleting a tag

297

Testing tag deletion 298 Adding a link to delete the
tag 299 Actually removing a tag 302




11.5

Finding tags

303

Testing search 303 Searching by state with
Searcher 305 Searching by state 307 Search, but
without the search 309




11.6

12

Summary

Sending email
12.1



310

312

Sending ticket notifications

313

Automatically watching a ticket 314 Using observers 315
Defining the watchers association 316 Introducing Action
Mailer 318 An Action Mailer template 320 Delivering
HTML emails 322









xii

CONTENTS

12.2

Subscribing to updates

325

Testing comment subscription 325 Automatically adding a user
to a watchlist 327 Unsubscribing from ticket notifications 328




12.3

Real-world email 333
Testing real-world email 334
Connecting to Gmail 337

12.4

Receiving emails

340

Setting a reply-to address

12.5

13

Summary

340



Receiving a reply

342

345

Designing an API
13.1

Configuring Action Mailer 336



347

The projects API

349

Your first API 351 Serving an API 354
API
authentication 355 Error reporting 356 Serving
XML 358 Creating projects 360 Restricting access to only
admins 362 A single project 365 No project for you! 368
Updating a project 370 Exterminate! 372


















13.2
13.3

Beginning the tickets API
Rate limiting 377

374

One request, two request, three request, four 377
thanks! 379 Back to zero 380



No more,



13.4

Versioning an API

381

Creating a new version

13.5

14

Summary

381

384

Deployment 385
14.1

Server setup

386

Setting up a server using VirtualBox
base 388

14.2
14.3

RVM and Ruby

389

Installing RVM

389



14.4

Installing Ruby

Creating a user for the app
Key-based authentication
authentication 393

The database server

386

391



Installing the

390

391


Disabling password

394

Creating a database and user

394



Ident authentication

395


xiii

CONTENTS

14.5

Deploy away!

395

Deploy keys 396 Configuring Capistrano 397 Setting up
the deploy environment 400 Deploying the application 401
Bundling gems 403 Choosing a database 405








14.6

Serving requests 407
Installing Passenger 408

14.7

15

Summary

An init script 410



410

Alternative authentication 412
15.1
15.2

How OAuth works 413
Twitter authentication 415
Setting up OmniAuth 415 Registering an application with
Twitter 416 Setting up an OmniAuth testing
environment 417 Testing Twitter sign-in 419






15.3

GitHub authentication 425
Registering and testing GitHub auth

15.4

16

Summary

433

Basic performance enhancements
16.1

Pagination



Paginating an interface

437

Database query enhancements 444
Eager loading

16.3

434

435

Introducing Kaminari 436
Paginating an API 443

16.2

425

445



Database indexes

Page and action caching

446

448

Caching a page 448 Caching an action 451 Cache
sweepers 454 Client-side caching 457 Caching page
fragments 460






16.4
16.5

17

Background workers
Summary 466

Engines
17.1
17.2
17.3



462

468

A brief history of engines 469
Why engines are useful 470
Brand-new engine 471
Creating an engine 471
Engine routing 476



The layout of an engine

472


xiv

CONTENTS

17.4

Setting up a testing environment
Removing Test::Unit
Capybara 481

17.5

479



478

Installing RSpec and

Writing your first engine feature 482
Your first Capybara test 483 Setting up routes 484 The
topics controller 485 The index action 485 The new
action 488 The create action 489 The show action 490
Showing an association count 492










17.6
17.7



Adding more posts to topics 493
Classes outside your control 497
Engine configuration 497 A fake User model 500
Authenticating topics 501 Adding authorship to topics
Post authentication 506 Showing the last post 509





17.8
17.9
17.10

18

Releasing as a gem 512
Integrating with an application 513
Summary 514

Rack-based applications
18.1

516

Building Rack applications
A basic Rack application

18.2

518

Building bigger Rack applications
You’re breaking up 522
application 524

18.3

522

Running a combined Rack



Mounting a Rack application with Rails
Mounting Heartbeat 526
The API, by Sinatra 528

18.4

517

Middleware




525

Introducing Sinatra 527
Basic error checking 532

533

Middleware in Rails 534 Investigating
ActionDispatch::Static 536 Crafting middleware 538




18.5
appendix A
appendix B

Summary

540

Why Rails? 541
Tidbits 546
index 551

505


preface
This book has been through quite the development process! It began in 2008 with
Michael Ivey, Yehuda Katz, and Ezra Zygmuntowicz and was called Merb in Action. Since
then it has changed name and hands a couple of times, winding up with people such as
James Cox and the great Mike Gunderloy, the latter of whom is probably most famous
for his work on Factsheet Five and many . NET books, not to mention being one of the
founding members of the RailsBridge (http://railsbridge.org) organization.
Then, somehow, I became involved with this book.
I received an email on a cold April morning in 2010 from Christina Rudloff at
Manning asking if I would have any interest in joining the project. I was exceptionally
excited! I had been writing short blog posts about Rails for years, and the idea of
focusing that effort into writing a book made me extremely happy. Long story short:
Yehuda Katz liked what he saw on my blog and wanted me to join the project. Working
with Yehuda has been brilliant. He’s got to be one of the smartest and most patient
people I have ever met.
Shortly after receiving that initial email from Christina, I talked with another person from Manning, Michael Stephens, first via email and then very late at night over
the phone (we are on different continents) about the project. I worked out the initial
chapter layout, and I distinctly remember one thing that Michael asked me: “You
know what you’re getting yourself into, right?” I thought “Sure, I’ve written blog posts
before, how hard could it be?” and replied in much the same manner. How little did
I know!
Since then, I have learned a lot about the book-writing process. For starters, it
involves a lot more than just the two people and the publishing company on the front

xv


xvi

PREFACE

cover. It also takes a very long time to write a book. This book has been my life for the
past year and a bit. I’ve spent many weekends, mornings before work, and evenings
after work (and way too often, time even in my dreams) writing chapters for this book.
I’ve talked about it (perhaps too much) as well. It’s become such a running joke
among people I know that when I’m introduced, they ask, “Do you know he’s writing a
book?”
Writing is sometimes easy, but other times it can be a struggle to come up with anything at all. There have been bad days, sure, but the good days outnumber those massively. The feeling of achievement you get when you finish a chapter, or even a section,
is awesome. Receiving positive feedback from people has been a huge boon to completing this book.
Now, in 2011, the book is finally done, and what an amazing feeling that is! I’d like
to think that it offers a unique perspective on developing a full Ruby on Rails application from scratch in the same (or at least, similar) manner that people are developing
Rails applications at this time. It’s also the first book to cover the latest features of
Rails found in version 3.1.
RYAN BIGG


acknowledgments
This has been an amazing process, full of amazing people. A large portion of this
book would not have been possible without the support of my employer, Mikel Lindsaar, and company, RubyX, allowing me to take time off to write the book. The support of the community at large has also been enormous in helping me complete this
book. Winning the Ruby Hero award at RailsConf, partially due to my work on this
very book, was the highlight of my career so far. After I won the award, Mikel also provided me with a new laptop at no expense to replace my previous one that was three
years old. Bloody champion!
Of course, a lot of this wouldn’t have been as easy if it wasn’t for the Rails Core
Team’s valiant efforts on their maintenance of the framework over the years and their
constant focus on improving people’s lives on an almost daily basis. Also there are
Yehuda Katz, Carl Lerche, and André Arko to thank for their work on an important
part of developing not only Rails applications, but also Ruby libraries such as Bundler
and Thor. These people are my idols, and I love them dearly.
Through a Rails-based review system called Twist that I built myself over a single
day, I’ve collected more than 1,200 notes from people from around the world who
have been reviewing the book as I have been writing it. A special mention goes to the
three people who’ve left the most notes in Twist: Roy Hacker, Deryl Doucette, and
Peter Ley. An almost-as-special mention goes to the 33 other people who’ve also left
notes. Without your help, this book wouldn’t be half as brilliant as it is today.
Also thanks to Tim McEwan for the ideas for the engines chapter, Chris Darroch
for an initial read-through of the first chapters, and Rob Zolkos for helping with some

xvii


xviii

ACKNOWLEDGMENTS

gnarly ePub Ruby and XLST code. And yes, thanks to Andrew Snow for assisting with a
difficult moral problem in chapter 16 at Railscamp in June 2011.
In addition to those who’ve been leaving notes in Twist, there are the people at
Manning. First, thanks to Christina Rudloff for the initial contact and Michael Stephens for the late-night chats and management of the process. Candace Gillhooley
and Nick Chase have also been enormously helpful.
Cynthia Kane, my development editor at Manning, is particularly special. Her job
was to tell me when I was doing things wrong, such as not segueing between sections
or making the text flow too fast, and to leave me notes such as “FIGURE!!!” when I
needed an image to go along with the text. Our almost weekly catch-ups were well
worthwhile; it was great always having someone there, prodding me for more content
and talking through the process. Marjan Bace, fearless leader of Manning Publications, should also be credited for supporting this project for as long as it has been
around.
The production team at Manning, including Troy Mott, has been great throughout
this process too. The extreme focus they’ve shown in finishing this book is stunning. I
also need to mention the wonderful work by Doug Warren in the final technical
proofing of the book, as well as Manning’s copyeditors, who touched up basically
every single paragraph in the book.
Special thanks to the reviewers who took time out of their busy schedules to provide feedback on the manuscript at different stages during development. They
include Jason Rogers, Craig Smith, Emmanuel Asante, Chad Moone, Dr. Jamie P. Finlay, Dave Nicolette, Grant Oladipo, Jean-Philippe Castro, Americo Savinon, Thomas
Athanas, Chris Kelly, Greg Vaughn, Pete Helgren, Joshua R Cronemeyer, Peter Melo,
Robby O’Connor, Philip Hallstrom, Curtis Miller, Patrick Peak, Anthony J. Topper,
Brian Rose, Daniel Bretoi, Wesley Moxam, Jon Agnes, and David Workman
Finally, my friends and family have been amazing throughout my entire life, all the
way from my parents—who supported my career choice in Ruby on Rails and technical writing, even though they paid for me to study Network Admin at TAFE and always
told me that I should “get out the house more”—to my current housemate, who
accepts that we don’t see much of each other (or at least I think so). You’re all wonderful people, and I hope now that the book is over I will see more of you. I would list
you all here if only it didn’t require this book to be printed in a multivolume series.
RYAN BIGG
Rails 3 in Action is a long-time coming. To give you some perspective, the book was
originally called Merb in Action, and it managed a perpetual beta through the Merb
merge, the release of Rails 3.0, and is finally ready just in time for Rails 3.1.
I can say with confidence that Rails 3 in Action would not exist without the hard,
tireless work of Ryan Bigg. It was Ryan’s idea to focus the book around real-world testing from the ground up, and it makes Rails 3 in Action the first book for Rails practitioners that teaches Rails the way professional Rails developers do it.


ACKNOWLEDGMENTS

xix

Since we merged Merb with Rails, I have had the benefit of not insignificant support from friends and family, who helped keep me on course in the long process that
eventually delivered Rails 3.0. I want to especially call out Aaron Patterson, José Valim,
Santiago Pastorino, and Xavier Noria, who stepped up and brought life back to a community that was starting to show signs of age by the time Rails 2.3 hit the shelves. And
Carl Lerche, who helped me keep focus on doing things right, even when it was
tempting not to.
Finally, I would be remiss if I didn't thank my wife, Leah, who has been there for
me through the amazing trajectory of my development career, through good times
and bad. Without her, I would have given up long ago.
YEHUDA KATZ


about this book
Ruby on Rails is a leading web application framework built on top of the fantastic
Ruby programming language. Both the language and the framework place an
extreme emphasis on having a principle of least surprise and getting out of the way of
the developers using it.
Ruby on Rails has been growing at a rapid pace, with large internet companies
such as Yellow Pages and Groupon using it for their core functionality. With the latest
release of Rails, version 3.1, comes a set of changes that improve the already brilliant
framework that has been constructed over the past seven years. The fantastic community around the framework has also been growing at a similar pace.
This book is designed to take you through developing a full-featured Rails application from step one, showing you exactly how professionals in the real world are developing applications right now.

Who should read this book
This book is primarily for those who are looking to begin working with the Ruby on
Rails framework and who have some prior experience with Ruby, although that is not
entirely necessary.
Later chapters, such as chapter 13, “Designing an API,” chapter 17, “Engines,” and
chapter 18, “Rack-based applications,” delve into more advanced topics, so these chapters are suitable for people who already have a foundation with Rails and are looking
to expand their skillset a little further.
If you’re looking for a book that teaches you the same practices that are used in
the real world, then this is the book you are looking for.

xx


ABOUT THIS BOOK

xxi

Roadmap
Chapter 1 introduces the Ruby on Rails framework and begins to show how you can
develop the beginnings of an application.
Chapter 2 shows off test-driven development and behavior-driven development,
which are two core concepts in this book and for developing Rails applications. By
testing the code you write, you can be assured that it’s always working that way.
Chapters 3 and 4 discuss the application you develop in this book—a project-management app of sorts—and delve into the core concepts of a Rails application. They
also look at developing the first core features of your application.
Chapter 5 begins an introduction to nested resources, building on top of the features developed in the previous two chapters.
Chapter 6 introduces authentication, requiring users to sign in to the application
before they can perform certain tasks.
Chapter 7 builds on the work in chapter 6 by adding new areas of the application
that are accessible only to users with a certain flag set in the database. You also use
namespaces for the first time.
Chapter 8 builds on the basic authorization created in chapter 7, fleshing it out
into something neater and more scalable.
In chapter 9, you learn about file uploading using the Paperclip gem. In this chapter you also learn about testing parts of your application that use JavaScript and about
CoffeeScript, a neater language that compiles down to JavaScript.
Chapter 10 builds not one but two new features for the application, adding the
ability to comment on a ticket as well as track the ticket’s lifecycle through varying
states.
In chapter 11, you add a feature that lets users assign tags to tickets so they can be
easily grouped. You also add a feature to allow users to search for tickets matching a
certain state or tag, or both.
Chapter 12 begins our foray into dealing with email in a Rails application. You’ll
see not only how to send email but also how to receive messages and parse them into
meaningful data in your application.
Chapter 13 involves creating an API for the project resources in an application
that provide other applications with a standardized way to access your application’s
data. We also look at token-based authentication and how to create multiple versions
of an API.
In chapter 14, you deploy the application to an Ubuntu box and set it up to act like
a normal web server using a RubyGem called Passenger and a web server called nginx.
In chapter 15, you create a “nice to have” feature: the ability to sign up or sign in
using either Twitter or GitHub. When this is complete, people are no longer required
to provide you with an email and password when they sign up; instead, they can use
GitHub and Twitter as authentication providers.


xxii

ABOUT THIS BOOK

By chapter 16, your application is all grown up and needs to handle any kind of
performance issues it encounters. We cover basic performance enhancements, such
as pagination, database indexing, and page and fragment caching.
Chapter 17 introduces a new feature for Rails 3: engines. You develop one of your
own from scratch—a forum system—and then integrate it with the existing application.
Chapter 18 delves into the depths of Rack, explaining how Rack applications are
made and can be tied into Rails. The chapter also explains, and contains examples of,
middleware being used in Rails.

Code conventions and downloads
Code conventions in the book follow the style of other Manning books in the In Action
series. All code in listings and in text appears in a monospaced font like this to separate it from ordinary text. In some cases, the original source code has been reformatted to fit on the pages. In general, the original code was written with page-width
limitations in mind, but sometimes you may find a slight formatting difference
between the code in the book and that provided in the source download. In a few rare
cases, where long lines could not be reformatted without changing their meaning, the
book listings contain line-continuation markers. Code annotations accompany many
of the listings, highlighting important concepts. In many cases, numbered bullets link
to explanations that follow in the text.
Source code for all the working examples in this book is available for download
from the publisher’s website at www.manning.com/Rails3inAction.

Author Online
The purchase of Rails 3 in Action includes free access to a private forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and other users. To access and subscribe to
the forum, point your browser to www.manning.com/Rails3inAction, and click the
Author Online link. This page provides information on how to get on the forum once
you are registered, what kind of help is available, and the rules of conduct in the
forum.
Manning’s commitment to our readers is to provide a venue where a meaningful
dialogue between individual readers and between readers and the authors can take
place. It’s not a commitment to any specific amount of participation on the part of the
authors, whose contribution to the book’s forum remains voluntary (and unpaid). We
suggest you try asking the authors some challenging questions, lest their interest stray!
The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.


about the authors
RYAN BIGG has been developing Ruby on Rails since version 1.2 and can be found
helping out the community by answering questions on IRC or StackOverflow or writing documentation. He currently works for a web consultancy based in Sydney called
RubyX.
YEHUDA KATZ is well known not only for his work on this third version of Ruby on
Rails, but also for other web-related projects such as jQuery, Bundler, Merb, and
SproutCore. He currently works for Strobe in San Francisco as a lead developer on
SproutCore and is the coauthor of Manning’s jQuery in Action, Second Edition.

xxiii


about the cover illustration
The figure on the cover of Rails 3 in Action is captioned “A Soldier.” The illustration is
taken from a nineteenth-century edition of Sylvain Maréchal’s four-volume compendium of regional and military dress customs published in France. Each illustration is
finely drawn and colored by hand. The rich variety of Maréchal’s collection reminds
us vividly of how culturally apart the world’s towns and regions were just 200 years ago.
Isolated from each other, people spoke different dialects and languages. In the streets
or in the countryside, it was easy to identify where they lived and what their trade or
station in life was just by their dress.
Dress codes have changed since then and the diversity by region, so rich at the
time, has faded away. It is now hard to tell apart the inhabitants of different continents, let alone different towns or regions. Perhaps we have traded cultural diversity
for a more varied personal life—certainly for a more varied and fast-paced technological life.
At a time when it is hard to tell one computer book from another, Manning celebrates the inventiveness and initiative of the computer business with book covers
based on the rich diversity of regional life of two centuries ago, brought back to life by
Maréchal’s pictures.

xxiv


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×