Flex
Flexible Rails
FLEX 3 ON RAILS 2
PETER ARMSTRONG
MANNING
Greenwich (74° w. long.)
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. Sound View Court 3B fax:(609) 877-8256 Greenwich, CT 06830 email: orders@manning.com
Copyright © 2006-2007 by Peter Armstrong Version 2007-12-29 All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical means, including information storage and retrieval systems, without permission in writing from Peter Armstrong, except by a reviewer who may quote brief passages in areview.
Rails, Ruby on Rails, and the Rails logo are trademarks of David Heinemeier Hansson. Flash, Flex, and Flex Builder are trademarks of Adobe Systems Incorporated. Furthermore, 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 Peter Armstrong was aware of a trademark claim, thedesignations have been printed in initial capital letters or in all capitals. Much effort went into the preparation of this book. However, the publisher and author assume no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. The opinions expressed within are solely the personal opinions of Peter Armstrong.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% recycled and processed without the use of elemental chlorine.
ManningPublications Co. Sound View Court 3B Greenwich, CT 06830
Copyeditor: Tiffany Taylor Typesetter: Gordan Salinovic Cover designer: Leslie Haimes
ISBN 1-933988-50-9 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 13 12 11 10 09 08 07
For Caroline and Evan
brief contents
PART 1 GETTING STARTED ....................................................... 1
1 2 3
■ ■ ■Why are we here? Where are we going? 3 Hello World 14 Getting started 52
PART 2
BUILDING THE APPLICATION..................................... 103
4 5 6 7
■ ■ ■ ■
Creating the main Flex UI 105 Expanding the Rails code, RESTfully Flex on Rails 186 Validation 261
118
PART 3
REFACTORING .......................................................... 293
8 9
■ ■
Refactoring toCairngorm 295 Holding state on the client properly
369
PART 4
FINISHING UP........................................................... 419
10 11 12
■ ■ ■
Finishing the application 421 Refactoring to RubyAMF 468 Rails on AIR (Adobe Integrated Runtime)
vii
512
contents
foreword xvii preface xix acknowledgments xxii about this book xxiv about the cover illustration xxxi
PART 1GETTING STARTED ......................................... 1
Why are we here? Where are we going? 3
1.1 Overview of the features and strengths of Flex 3 and Rails 2 5
Overview of Flex 3 5 Overview of Rails 2 of using Flex 3 and Rails 2 together 7
■
1
5
■
Overview
1.2 1.3 1.4 1.5
Flash 9? Are you kidding me? History 9 A preview of the book 12 Summary 13
8
ix
xCONTENTS
2
Hello World 14
2.1 Installing everything
■ ■
16
■ ■
Installing Ruby 16 Installing Rails 17 Installing MySQL 18 Installing Flex 18 Installing a text editor or IDE (SDK users only) 21 Creating the Rails project 22 How to read the rest of this iteration 24
■ ■
2.2
Windows or Mac OS X + Flex Builder 3
■ ■ ■
25
Creating the Flex project 25 “Hello World” from Flex...
Regístrate para leer el documento completo.