1. Trang chủ
  2. » Công Nghệ Thông Tin

1593275722 {F4CD4FC6} rails crash course a no nonsense guide to rails development lewis 2014 10 16

298 245 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 298
Dung lượng 2,88 MB

Nội dung

Rails Crash Course Rails Crash Course Copyright © 2015 by Anthony Lewis All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher Printed in USA First printing 18 17 16 15 14   ISBN-10: 1-59327-572-2 ISBN-13: 978-1-59327-572-3 Publisher: William Pollock Production Editor: Serena Yang Cover Illustration: W Sullivan Interior Design: Octopod Studios Developmental Editor: Jennifer Griffith-Delgado Technical Reviewer: Xavier Noria Copyeditor: LeeAnn Pickrell Compositor: Susan Glinert Stevens Proofreader: James Fraleigh Indexer: Nancy Guenther For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc directly: No Starch Press, Inc 245 8th Street, San Francisco, CA 94103 phone: 415.863.9900; info@nostarch.com www.nostarch.com Library of Congress Cataloging-in-Publication Data Lewis, Anthony, 1975- author Rails crash course : a no-nonsense guide to Rails development / by Anthony Lewis pages cm ISBN 978-1-59327-572-3 ISBN 1-59327-572-2 Ruby (Computer program language) Ruby on rails (Electronic resource) I Title TK5105.8885.R83L49 2015 006.7'54 dc23 2014034816 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc Other product and company names mentioned herein may be the trademarks of their respective owners Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark The information in this book is distributed on an “As Is” basis, without warranty While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it Brief Contents Foreword by Xavier Noria xv Acknowledgments xvii Introduction xix Part I: Ruby on Rails Fundamentals Chapter 1: Ruby Fundamentals Chapter 2: Rails Fundamentals 19 Chapter 3: Models 29 Chapter 4: Controllers 43 Chapter 5: Views 57 Chapter 6: Deployment 75 Part II: Building a Social Networking App Chapter 7: Advanced Ruby 89 Chapter 8: Advanced Active Record 105 Chapter 9: Authentication 123 Chapter 10: Testing 141 Chapter 11: Security 163 Chapter 12: Performance 175 Chapter 13: Debugging 195 Chapter 14: Web APIs 205 Chapter 15: Custom Deployment 223 Solutions 239 Index 259 Conte nt s in De ta il Foreword by Xavier Noria xv Acknowledgments xvii Introduction xix Who This Book Is For Overview Installation Ruby, Rails, and Git Multiple Ruby Versions xx xx xxi xxi xxiii Part I Ruby on Rails Fundamentals Ruby Fundamentals Interactive Ruby Data Types Numbers Strings Symbols Arrays Hashes Booleans Constants Variables Control Flow Conditionals Iteration Methods Classes Class Methods Inheritance Summary Exercises Rails Fundamentals Your First Rails Application Rails Principles Convention over Configuration Don’t Repeat Yourself 10 10 11 11 12 14 15 17 17 18 18 19 20 21 21 22 Rails Architecture Model View Controller Rails Application Structure The app Directory The bin Directory The config Directory The db Directory The lib Directory The log Directory The public Directory The test Directory The tmp Directory The vendor Directory Rails Commands The gem Command The bundle Command The rake Command The rails Command Rails Scaffold Summary Exercises 22 22 22 23 23 23 23 23 24 24 24 24 25 25 25 25 25 26 26 26 27 28 28 Models 29 The Post Model Active Record Create, Read, Update, and Delete Create Read Update Delete More Active Record Methods Query Conditions Calculations Migrations The Schema Adding a Column Inside the Author Migration Validations Adding a Validation Testing Data Associations Generating the Model Adding Associations Using Associations Summary Exercises viii  Contents in Detail 29 30 30 31 32 33 33 34 34 35 35 36 37 37 38 38 39 39 39 40 40 42 42 Controllers 43 Representational State Transfer Routing Resources Custom Routes The Root Route Paths and URLs Controller Actions A Brief Detour from Actions Back to Controller Actions Adding Comments Summary Exercises 43 45 45 46 47 47 48 49 52 54 55 56 Views 57 Embedded Ruby Output Control Flow Comments Helpers URL Helpers Number Helpers Your Own Helpers The Posts Index Page Layouts Asset Tag Helpers CSRF Meta Tags Helper Yield Partials Collections Showing Comments Forms Form Helpers Form Errors Form Controls Comment Form Summary Exercises 58 58 58 59 59 59 60 61 61 64 65 66 67 67 67 68 69 70 70 71 72 74 74 Deployment 75 Version Control Git Setup Getting Started Basic Usage 75 76 76 76 77 Contents in Detail  ix Ind e x Numbers and Symbols 404.html file, 24 422.html file, 24 500.html file, 24 && (and) operator, 9–10 @ , for instance variables, 15 \ (backslash), for special characters, : (colon), for symbols, { } (curly braces) for blocks, 13 for hashes, :: (double-colon) operator, 91 " (double-quotes), for strings, == (equal) operator, ! (exclamation mark), at end of method name, => (hash rocket), 8–9 > (greater than) operator, < (less than) operator, and inheritance, 17 [...]... in case you are not familiar with it Ruby is a powerful programming language, but it is easy to learn, and with that quick introduction, you’ll know enough to begin Later, more advanced Ruby is explained Once you know some Ruby, you’re going to learn Rails All aspects of the framework are covered, including how to write models that get persisted easily in a database, how to validate data, how to handle... need to declare a variable in advance or specify a type Just assign a value to a name as shown here: irb(main):040:0> x = 10 => 10 10   Chapter 1 The variable x now refers to the number 10 Variable names are typically written in snake case, that is, all lowercase with underscores between words irb(main):041:0> first_name = "Matthew" => "Matthew" Variable names can include letters, numbers, and underscores,... modern and idiomatic Ruby on Rails But first things first Ruby on Rails is a web framework written in the Ruby programming language Think about Rails as a huge Ruby library: A Rails application is written in Ruby and uses the classes and core support provided by Ruby on Rails Therefore, you definitely have to know some Ruby in order to write Ruby on Rails applications! The first chapter of Rails Crash Course. .. here shows an example of each method, using the same hash just created: irb(main):029:0> another_guy.keys => [:name, :age] irb(main):030:0> another_guy.values => ["Ben", 20] Hashes are frequently used to represent data structures, as in these examples They are also sometimes used to pass named parameters to a method If a hash is the last (or only) argument to a method call, you can even leave off the... Rails Crash Course guides you step-by-step all the way through uploading your application to production platforms and seeing it run on the Internet That’s an amazing experience You’ll learn how to deploy to Heroku and how to deploy to a computer in the Amazon cloud While the servers needed to run an application for learning are small and free, they are the real thing: You’ll upload to the exact same... efficient Arrays An array represents a list of objects in Ruby You create an array by surrounding a list of objects with square brackets For example, let’s make an array of numbers: irb(main):021:0> list = [1, 2, 3] => [1, 2, 3] Ruby Fundamentals   7 Ruby arrays can contain any kind of object, even other arrays You can access individual elements of an array by passing a numeric index to the array’s []... You’ll learn about these fundamental aspects of the Rails culture explicitly in the second chapter of Rails Crash Course and implicitly by example throughout the book While the foundational ideas behind Ruby on Rails remain key, the framework has evolved Ruby on Rails has been extended here, shrunk there, iterated, and refined The world in which Rails applications live has also evolved Rails Crash Course. .. how to serve HTML, and so on Rails Crash Course covers all sides of Ruby on Rails, but then it takes you beyond the basics For example, you’ll learn some advanced Active Record, authentication, and how to write an application that provides a REST API, but you’ll also learn about testing, security, performance, debugging, and other practical concerns of writing real-world web applications Further, Rails. .. creating a Git repository to store your application and deploying your application to the web using Heroku Once you understand the fundamentals of Ruby and Ruby on Rails, you’re ready for more advanced topics Chapter 7: Advanced Ruby covers Ruby modules, the Ruby object model, and even a bit of metaprogramming Chapter 8: Advanced Active Record covers more advanced Active Record associations You’ll also... hashes are enclosed in curly braces Unlike an array index, a hash key can be of any data type For ­example, symbols are frequently used as hash keys When you need to access a value in a hash, just pass the corresponding key to the [] method, as shown next Attempting to access a key that does not exist returns nil irb(main):026:0> some_guy = { :name => "Tony", :age => 21 } => {:name=>"Tony", :age=>21} ... how to write models that get persisted easily in a database, how to validate data, how to handle web requests, how to serve HTML, and so on Rails Crash Course covers all sides of Ruby on Rails, ... run an application for learning are small and free, they are the real thing: You’ll upload to the exact same services big companies are deploying their applications to Rails Crash Course is a superb... Advanced Active Record Advanced Data Modeling Self Join Associations Many -to- Many Associations Single-Table Inheritance Polymorphic Associations The Social Application

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

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN