1937785564 {b6a1a852} agile web development with rails 4 ruby, thomas hansson 2013 10 11

439 597 0
1937785564 {b6a1a852} agile web development with rails 4 ruby, thomas   hansson 2013 10 11

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Early praise for Agile Web Development with Rails Agile Web Development with Rails is the Rails way to build real-world web apps—it’s definitive Rails itself relies on this book as a test suite Rails moves fast and AWDwR is always there, a backstage pass to the very latest ➤ Jeremy Kemper Member of the Rails core team This is an excellent way to quickly get up and running with Ruby and Rails The book is so good that Sam Ruby should change his name to Sam Rails ➤ Aaron Patterson Member of the Ruby and Rails core teams Like many, I started out with Ruby by reading an earlier version of Agile Web Development with Rails Many years (and a few updates) later, it’s still as good a resource for learning Rails as it has ever been, and this edition brings it right up to date with Rails ➤ Stephen Orr Lead developer, Made Media Agile Web Development with Rails Sam Ruby Dave Thomas David Heinemeier Hansson The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina 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, PragProg 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://pragprog.com The team that produced this book includes: Susannah Pfalzer (editor) Kim Wimpsett (copyeditor) David J Kelly (typesetter) Janet Furlow (producer) Juliet Benda (rights) Ellie Callahan (support) Copyright © 2013 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-13: 978-1-937785-56-7 Printed on acid-free paper Book version: P1.0—September 2013 Contents Acknowledgments ix Introduction xi Part I — Getting Started Installing Rails 1.1 Installing on Windows 1.2 Installing on Mac OS X 1.3 Installing on Linux 1.4 Choosing a Rails Version 1.5 Setting Up Your Development Environment 1.6 Rails and Databases Instant Gratification 2.1 Creating a New Application 2.2 Hello, Rails! 2.3 Linking Pages Together The 3.1 3.2 3.3 Architecture of Rails Applications Models, Views, and Controllers Rails Model Support Action Pack: The View and Controller 29 29 32 34 Introduction to Ruby 4.1 Ruby Is an Object-Oriented Language 4.2 Data Types 4.3 Logic 4.4 Organizing Structures 4.5 Marshaling Objects 4.6 Pulling It All Together 4.7 Ruby Idioms 37 37 39 43 45 48 49 50 4 12 15 15 17 24 Contents • vi Part II — Building an Application The 5.1 5.2 5.3 Depot Application Incremental Development What Depot Does Let’s Code Task A: Creating the Application 6.1 Iteration A1: Creating the Products Application 6.2 Iteration A2: Making Prettier Listings Maintenance 55 55 56 60 61 61 68 Task B: Validation and Unit Testing 7.1 Iteration B1: Validating! 7.2 Iteration B2: Unit Testing of Models 77 77 82 Task 8.1 8.2 8.3 8.4 8.5 C: Catalog Display Iteration C1: Creating the Catalog Listing Iteration C2: Adding a Page Layout Iteration C3: Using a Helper to Format the Price Iteration C4: Functional Testing of Controllers Iteration C5: Caching of Partial Results 91 91 96 100 101 104 Task 9.1 9.2 9.3 D: Cart Creation Iteration D1: Finding a Cart Iteration D2: Connecting Products to Carts Iteration D3: Adding a Button 107 107 108 110 10 Task 10.1 10.2 10.3 E: A Smarter Cart Iteration E1: Creating a Smarter Cart Iteration E2: Handling Errors Iteration E3: Finishing the Cart 119 119 124 128 11 Task 11.1 11.2 11.3 11.4 11.5 11.6 F: Add a Dash of Ajax Iteration F1: Moving the Cart Iteration F2: Creating an Ajax-Based Cart Iteration F3: Highlighting Changes Iteration F4: Hiding an Empty Cart Iteration F5: Making Images Clickable Testing Ajax Changes 135 136 142 146 149 152 154 Contents Task G: Check Out! 12.1 Iteration G1: Capturing an Order 12.2 Iteration G2: Atom Feeds 13 Task H: Sending Mail 13.1 Iteration H1: Sending Confirmation Emails 13.2 Iteration H2: Integration Testing of Applications 14 Task 14.1 14.2 14.3 14.4 I: Logging In Iteration I1: Adding Users Iteration I2: Authenticating Users Iteration I3: Limiting Access Iteration I4: Adding a Sidebar, More Administration 15 Task 15.1 15.2 15.3 15.4 J: Internationalization Iteration J1: Selecting the Locale Iteration J2: Translating the Storefront Iteration J3: Translating Checkout Iteration J4: Add a Locale Switcher 16 Task K: Deployment and Production 16.1 Iteration K1: Deploying with Phusion Passenger and MySQL 16.2 Iteration K2: Deploying Remotely with Capistrano 16.3 Iteration K3: Checking Up on a Deployed Application 234 242 248 Depot Retrospective 17.1 Rails Concepts 17.2 Documenting What We Have Done vii 12 17 • 159 159 172 177 177 184 191 191 197 202 204 211 211 215 222 229 233 253 253 256 Part III — Rails in Depth 18 Finding Your Way Around Rails 18.1 Where Things Go 18.2 Naming Conventions 261 261 270 19 Active Record 19.1 Defining Your Data 19.2 Locating and Traversing Records 19.3 Creating, Reading, Updating, and Deleting (CRUD) 19.4 Participating in the Monitoring Process 19.5 Transactions 275 275 280 284 298 304 Contents • viii 20 Action Dispatch and Action Controller 20.1 Dispatching Requests to Controllers 20.2 Processing of Requests 20.3 Objects and Operations That Span Requests 309 309 319 330 21 Action View 21.1 Using Templates 21.2 Generating Forms 21.3 Processing Forms 21.4 Uploading Files to Rails Applications 21.5 Using Helpers 21.6 Reducing Maintenance with Layouts and Partials 341 341 343 346 348 351 358 22 Migrations 22.1 Creating and Running Migrations 22.2 Anatomy of a Migration 22.3 Managing Tables 22.4 Advanced Migrations 22.5 When Migrations Go Bad 22.6 Schema Manipulation Outside Migrations 367 367 370 375 379 382 383 23 Nonbrowser Applications 23.1 A Stand-Alone Application Using Active Record 23.2 A Library Function Using Active Support 385 385 386 24 Rails’ Dependencies 24.1 Generating XML with Builder 24.2 Generating HTML with ERB 24.3 Managing Dependencies with Bundler 24.4 Interfacing with the Web Server with Rack 24.5 Automating Tasks with Rake 24.6 Survey of Rails’ Dependencies 393 393 395 397 400 404 405 25 Rails 25.1 25.2 25.3 25.4 Plugins Credit Card Processing with Active Merchant Beautifying Our Markup with Haml Pagination Finding More at RailsPlugins.org 411 411 413 416 418 26 Where to Go from Here A1 Bibliography Index 421 423 425 Acknowledgments Rails is constantly evolving and, as it does, so has this book Parts of the Depot application were rewritten several times, and all of the narrative was updated The avoidance of features as they become deprecated have repeatedly changed the structure of the book as what was once hot became just lukewarm So, this book would not exist without a massive amount of help from the Ruby and Rails communities To start with, we had a number of incredibly helpful formal reviewers of drafts of this book Jeremy Anderson Andrea Barisone Ken Coar Jeff Cohen Joel Clermont Geoff Drake Jeremy Frens Pavan Gorakavi Michael Jurewitz Mikel Lindsaar Nigel Lowry Stephen Orr Aaron Patterson Paul Rayner Martijn Reuvers Doug Rhoten Gary Sherman Tibor Simic Gianluigi Spagnuolo Davanum Srinivas Charley Stran Federico Tomassetti Stefan Turalski José Valim Additionally, each edition of this book has been released as a beta book: early versions were posted as PDFs, and people made comments online And comment they did; over time more than 1,000 suggestions and bug reports were posted The vast majority ended up being incorporated, making this book immeasurably more useful than it would have been While thanks go out to all for supporting the beta book program and for contributing so much valuable feedback, a number of contributors went well beyond the call of duty Manuel E Vidaurre Arenas Seth Arnold Will Bowlin Andy Brice Jason Catena Victor Marius Costan report erratum • discuss Acknowledgments David Hadley Jason Holloway David Kapp Trung LE Kristian Riiber Mandrup mltsy Steve Nicholson Jim Puls Johnathan Ritzi Leonel S Kim Shrier Don Smith Joe Straitiff Martin Zoller • x Finally, the Rails core team has been incredibly helpful, answering questions, checking out code fragments, and fixing bugs—even to the point where part of the release process includes verifying that new releases of Rails don’t break the examples provided in this book.1 A big “thank you” to the following: Rafael Franỗa (rafaelfranca) Guillermo Iguaran (guilleiguaran) Jeremy Kemper (bitsweat) Yehuda Katz (wycats) Michael Koziarski (nzkoz) Santiago Pastorino (spastorino) Aaron Patterson José Valim (josevalim) Sam Ruby rubys@intertwingly.net August 2013 https://github.com/rails/rails/blob/master/RELEASING_RAILS.rdoc#is-sam-rubyhappy if-not-make-him-happy report erratum • discuss APPENDIX Bibliography [Bur11] Trevor Burnham CoffeeScript: Accelerated JavaScript Development The Pragmatic Bookshelf, Raleigh, NC and Dallas, TX, 2011 [CC11] Hampton Catlin and Michael Lintorn Catlin Pragmatic Guide to Sass The Pragmatic Bookshelf, Raleigh, NC and Dallas, TX, 2011 [TFH13] David Thomas, Chad Fowler, and Andrew Hunt Programming Ruby: The Pragmatic Programmer’s Guide The Pragmatic Bookshelf, Raleigh, NC and Dallas, TX, Fourth Edition, 2013 report erratum • discuss Index SYMBOLS ! suffix, 50 #, 39 #{…}, 40 %r{…}, 42 %{…}, 69 & prefix, 44 /…/, 42 : prefix, 38 , 21 , 395

Ngày đăng: 07/01/2017, 20:54

Mục lục

  • Cover

  • Table of Contents

  • Acknowledgments

  • Introduction

    • Rails Simply Feels Right

    • Rails Is Agile

    • Who This Book Is For

    • How to Read This Book

    • Part 1—Getting Started

      • 1. Installing Rails

        • Installing on Windows

        • Installing on Mac OS X

        • Installing on Linux

        • Choosing a Rails Version

        • Setting Up Your Development Environment

        • Rails and Databases

        • 2. Instant Gratification

          • Creating a New Application

          • Hello, Rails!

          • Linking Pages Together

          • 3. The Architecture of Rails Applications

            • Models, Views, and Controllers

            • Rails Model Support

            • Action Pack: The View and Controller

            • 4. Introduction to Ruby

              • Ruby Is an Object-Oriented Language

Tài liệu cùng người dùng

Tài liệu liên quan