Rails 4 in Action: Revised Edition of Rails 3 in Action Ryan Bigg, Yehuda Katz, Steve Klabnik, and Rebecca Skinner Copyright 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 761 Shelter Island, NY 11964 Email: [email protected] ©2015 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. Development editor: Susan Conant 20 Baldwin Road Technical editor: Steven Jenkins PO Box 761 Copyeditor: Andy Carroll Shelter Island, NY 11964 Proofreader: Katie Tennant Technical proofreader: Doug Warren Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617291098 Printed in the United States of America Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 20 19 18 17 16 15 Brief Table of Contents Copyright Brief Table of Contents Table of Contents Praise for Rails 3 in Action Preface Acknowledgments About this Book Chapter 1. Ruby on Rails, the framework Chapter 2. Testing saves your bacon Chapter 3. Developing a real Rails application Chapter 4. Oh, CRUD! Chapter 5. Nested resources Chapter 6. Authentication Chapter 7. Basic access control Chapter 8. Fine-grained access control Chapter 9. File uploading Chapter 10. Tracking state Chapter 11. Tagging Chapter 12. Sending email Chapter 13. Deployment Chapter 14. Designing an API Chapter 15. Rack-based applications Appendix A. Installation guide Appendix B. Why Rails? Index List of Figures List of Tables List of Listings Table of Contents Copyright Brief Table of Contents Table of Contents Praise for Rails 3 in Action Preface Acknowledgments About this Book Chapter 1. Ruby on Rails, the framework 1.1. Ruby on Rails overview 1.1.1. Benefits 1.1.2. Ruby gems 1.1.3. Common terms 1.1.4. Rails in the wild 1.2. Developing your first application 1.2.1. Installing Rails 1.2.2. Generating an application 1.2.3. Starting the application 1.2.4. Scaffolding 1.2.5. Migrations 1.2.6. Viewing and creating purchases 1.2.7. Validations 1.2.8. Routing 1.2.9. Updating 1.2.10. Deleting 1.3. Summary Chapter 2. Testing saves your bacon 2.1. Using TDD and BDD to save your bacon 2.2. Test-driven development basics 2.2.1. Writing your first test 2.2.2. Saving bacon 2.3. Behavior-driven development basics 2.3.1. Introducing RSpec 2.3.2. Writing your first spec 2.3.3. Running the spec 2.3.4. Much more bacon 2.3.5. Expiring bacon 2.4. Summary Chapter 3. Developing a real Rails application 3.1. First steps 3.1.1. The application story 3.1.2. Laying the foundations 3.2. Version control 3.2.1. Getting started with GitHub 3.2.2. Configuring your Git client 3.3. Application configuration 3.3.1. The Gemfile and generators 3.3.2. Database configuration 3.4. Beginning your first feature 3.4.1. Creating projects 3.4.2. Defining a controller action 3.4.3. RESTful routing 3.4.4. Committing changes 3.4.5. Setting a page title 3.4.6. Validations 3.5. Summary Chapter 4. Oh, CRUD! 4.1. Viewing projects 4.1.1. Introducing Factory Girl 4.1.2. Adding a link to a project 4.2. Editing projects 4.2.1. The edit action 4.2.2. The update action 4.3. Deleting projects 4.4. What happens when things can’t be found 4.4.1. Visualizing the error 4.4.2. Handling the ActiveRecord::RecordNotFound exception 4.5. Styling the application 4.5.1. Installing Bootstrap 4.5.2. Improving the page’s header 4.5.3. Improving the show view 4.5.4. Semantic styling 4.5.5. Using Simple Form 4.5.6. Adding a navigation bar 4.5.7. Responsive styling 4.6. Summary Chapter 5. Nested resources 5.1. Creating tickets 5.1.1. Nested routing helpers 5.1.2. Creating a tickets controller 5.1.3. Demystifying the new action 5.1.4. Defining a has_many association 5.1.5. Creating tickets in a project 5.1.6. Finding tickets scoped by project 5.1.7. Ticket validations 5.2. Viewing tickets 5.2.1. Listing tickets 5.2.2. Culling tickets 5.3. Editing tickets 5.3.1. The ticket-editing spec 5.3.2. Adding the edit action 5.3.3. Adding the update action 5.4. Deleting tickets 5.5. Summary Chapter 6. Authentication 6.1. Using Devise 6.2. Adding sign-up 6.3. Adding sign-in and sign-out 6.3.1. Adding sign-in 6.3.2. Adding sign-out 6.3.3. Styling the Devise views 6.4. Linking tickets to users
Description: