Ruby on Rails™ 3 Tutorial

Total Page:16

File Type:pdf, Size:1020Kb

Ruby on Rails™ 3 Tutorial Praise for Ruby on Rails™ 3 Tutorial RailsTutorial.org: Michael Hartl’s awesome new Rails Tutorial The Ruby on Rails ™ 3 Tutorial: Learn Rails by Example by Michael Hartl has become a must read for developers learning how to build Rails apps. —Peter Cooper, editor of Ruby Inside Very detailed and hands-on Rails Tutorial! Great job! I’m learning Rails, and found your tutorial to be one of the most detailed and hands-on guides. Besides many details of Rails, it also taught me about Git, Heroku, RSpec, Webrat, and most important (at least to me), it emphasized the Test-Driven Development (TDD) methodology. I learned a lot from your tutorial. Keep up the good job! Thanks so much for sharing it. —Albert Liu, senior manager, Achievo Corporation. Ruby on Rails Tutorial is the best! Just wanted to say that your Ruby on Rails tutorial is the best! I’ve been trying for a while to wrap my head around Rails. Going through your tutorial, I’m finally feeling comfortable in the Rails environment. Your pedagogical style of gradually introducing more complex topics while at the same time giving the reader the instant gratification and a sense of accomplishment with working examples really works for me. I also like the tips and suggestions that give me a sense of learning from a real Rails insider. Your e-mail response to a problem I ran into is an example of your generous sharing of your experience. —Ron Bingham, CEO, SounDBuytz I love the writing style of the Rails Tutorial I love the writing style of the Rails Tutorial, and there is so much content that is different from other Rails books out there, making it that much more valuable...Thanks for your work! —Allen Ding RUBY ON RAILS™ 3 TUTORIAL Addison-Wesley Professional Ruby Series Obie Fernandez, Series Editor Visit informit.com/ruby for a complete list of available products. he Addison-Wesley Professional Ruby Series provides readers T with practical, people-oriented, and in-depth information about applying the Ruby platform to create dynamic technology solutions. The series is based on the premise thatthe need for expert reference books, written by experienced practitioners, will never be satisfied solely by blogs and the Internet. RUBY ON RAILS™ 3 TUTORIAL Learn Rails™ by Example Michael Hartl Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed Editor-in-Chief as trademarks. Where those designations appear in this book, and the publisher was aware of a Mark Taub trademark claim, the designations have been printed with initial capital letters or in all capitals. Executive Acquisitions Editor Debra Williams Cauley The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is Managing Editor assumed for incidental or consequential damages in connection with or arising out of the use of the John Fuller information or programs contained herein. Project Editor Elizabeth Ryan The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to Copy Editor your business, training goals, marketing focus, and branding interests. For more information, please Erica Orloff contact: Indexer Claire Splan U.S. Corporate and Government Sales (800) 382-3419 Proofreader [email protected] Claire Splan For sales outside the United States please contact: Publishing Coordinator International Sales Kim Boedigheimer [email protected] Cover Designer Gary Adair Visit us on the Web: informit.com/aw Compositor Library of Congress Cataloging-in-Publication Data Glyph International Hartl, Michael. Ruby on rails 3 tutorial : learn Rails by example / Michael Hartl. p. cm. Includes index. ISBN-10: 0-321-74312-1 (pbk. : alk. paper) ISBN-13: 978-0-321-74312-1 (pbk. : alk. paper) 1. Ruby on rails (Electronic resource) 2. Web site development. 3. Ruby (Computer program language) I. Title. TK5105.8885.R83H37 2011 005.1 17–dc22 2010039450 Copyright © 2011 Michael Hartl All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc. Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax: (617) 671-3447 The source code in Ruby on Rails ™ 3 Tutorial is released under the MIT License. ISBN 13: 978-0-321-74312-1 ISBN 10: 0-321-74312-1 Text printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, Michigan First printing, December 2010 Contents Foreword by Derek Sivers xv Foreword by Obie Fernandez xvii Acknowledgments xix About the Author xxi Chapter 1 From Zero to Deploy 1 1.1 Introduction 3 1.1.1 Comments for Various Readers 4 1.1.2 “Scaling” Rails 7 1.1.3 Conventions in This Book 7 1.2 Up and Running 9 1.2.1 Development Environments 9 1.2.2 Ruby, RubyGems, Rails, and Git 11 1.2.3 The First Application 15 1.2.4 Bundler 16 1.2.5 rails server 20 1.2.6 Model-View-Controller (MVC) 22 1.3 Version Control with Git 24 1.3.1 Installation and Setup 24 1.3.2 Adding and Committing 26 1.3.3 What Good Does Git Do You? 28 1.3.4 GitHub 29 1.3.5 Branch, Edit, Commit, Merge 31 vii viii Contents 1.4 Deploying 35 1.4.1 Heroku Setup 36 1.4.2 Heroku Deployment, Step One 37 1.4.3 Heroku Deployment, Step Two 37 1.4.4 Heroku Commands 39 1.5 Conclusion 40 Chapter 2 A Demo App 41 2.1 Planning the Application 41 2.1.1 Modeling Users 43 2.1.2 Modeling Microposts 44 2.2 The Users Resource 44 2.2.1 A User Tour 46 2.2.2 MVC in Action 49 2.2.3 Weaknesses of This Users Resource 58 2.3 The Microposts Resource 58 2.3.1 A Micropost Microtour 58 2.3.2 Putting the micro in Microposts 61 2.3.3 A User has_many Microposts 63 2.3.4 Inheritance Hierarchies 66 2.3.5 Deploying the Demo App 68 2.4 Conclusion 69 Chapter 3 Mostly Static Pages 71 3.1 Static Pages 74 3.1.1 Truly Static Pages 75 3.1.2 Static Pages with Rails 78 3.2 Our First Tests 84 3.2.1 Testing Tools 84 3.2.2 TDD: Red, Green, Refactor 86 3.3 Slightly Dynamic Pages 103 3.3.1 Testing a Title Change 103 3.3.2 Passing Title Tests 106 3.3.3 Instance Variables and Embedded Ruby 108 3.3.4 Eliminating Duplication with Layouts 112 3.4 Conclusion 115 3.5 Exercises 116 Contents ix Chapter 4 Rails-Flavored Ruby 119 4.1 Motivation 119 4.1.1 A title Helper 119 4.1.2 Cascading Style Sheets 122 4.2 Strings and Methods 125 4.2.1 Comments 125 4.2.2 Strings 126 4.2.3 Objects and Message Passing 129 4.2.4 Method Definitions 132 4.2.5 Back to the title Helper 133 4.3 Other Data Structures 134 4.3.1 Arrays and Ranges 134 4.3.2 Blocks 137 4.3.3 Hashes and Symbols 139 4.3.4 CSS Revisited 142 4.4 Ruby Classes 144 4.4.1 Constructors 144 4.4.2 Class Inheritance 145 4.4.3 Modifying Built-In Classes 148 4.4.4 A Controller Class 150 4.4.5 A User Class 152 4.5 Exercises 154 Chapter 5 Filling in the Layout 157 5.1 Adding Some Structure 157 5.1.1 Site Navigation 159 5.1.2 Custom CSS 164 5.1.3 Partials 171 5.2 Layout Links 177 5.2.1 Integration Tests 178 5.2.2 Rails Routes 181 5.2.3 Named Routes 183 5.3 User Signup: A First Step 186 5.3.1 Users Controller 186 5.3.2 Signup URL 188 5.4 Conclusion 191 5.5 Exercises 191 x Contents Chapter 6 Modeling and Viewing Users, Part I 193 6.1 User Model 194 6.1.1 Database Migrations 196 6.1.2 The Model File 201 6.1.3 Creating User Objects 203 6.1.4 Finding User Objects 207 6.1.5 Updating User Objects 208 6.2 User Validations 210 6.2.1 Validating Presence 210 6.2.2 Length Validation 217 6.2.3 Format Validation 218 6.2.4 Uniqueness Validation 222 6.3 Viewing Users 227 6.3.1 Debug and Rails Environments 227 6.3.2 User Model, View, Controller 230 6.3.3 A Users Resource 232 6.4 Conclusion 236 6.5 Exercises 237 Chapter 7 Modeling and Viewing Users, Part II 239 7.1 Insecure Passwords 239 7.1.1 Password Validations 240 7.1.2 A Password Migration 244 7.1.3 An Active Record Callback 247 7.2 Secure Passwords 250 7.2.1 A Secure Password Test 251 7.2.2 Some Secure Password Theory 252 7.2.3 Implementing has_password? 254 7.2.4 An Authenticate Method 258 7.3 Better User Views 262 7.3.1 Testing the User Show Page (With Factories) 263 7.3.2 A Name and A Gravatar 268 7.3.3 A User Sidebar 276 7.4 Conclusion 279 7.4.1 Git Commit 279 7.4.2 Heroku Deploy 280 7.5 Exercises 280 Contents xi Chapter 8 Sign Up 283 8.1 Signup Form 283 8.1.1 Using form_for 286 8.1.2 The Form HTML 288 8.2 Signup Failure 292 8.2.1 Testing Failure 292 8.2.2 A Working Form 295 8.2.3 Signup Error Messages 299 8.2.4 Filtering Parameter Logging 303 8.3 Signup Success 305 8.3.1 Testing Success 305 8.3.2 The Finished Signup Form 308 8.3.3 The Flash 308 8.3.4 The First Signup 312 8.4 RSpec Integration Tests 313 8.4.1 Integration Tests with Style 315 8.4.2 Users Signup Failure Should not Make a New User 315 8.4.3 Users Signup Success Should Make a New User 319 8.5 Conclusion 321 8.6 Exercises 321 Chapter 9 Sign In, Sign Out 325 9.1 Sessions 325 9.1.1 Sessions Controller 326 9.1.2 Signin Form 328 9.2 Signin Failure 332 9.2.1 Reviewing form Submission 333 9.2.2
Recommended publications
  • Github Essentials.Pdf
    [ 1 ] GitHub Essentials Unleash the power of collaborative workflow development using GitHub, one step at a time Achilleas Pipinellis BIRMINGHAM - MUMBAI GitHub Essentials Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2015 Production reference: 1280915 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78355-371-6 www.packtpub.com Credits Author Copy Editor Achilleas Pipinellis Trishya Hajare Reviewer Project Coordinator Umesh Ram Sharma Shweta H Birwatkar Commissioning Editor Proofreader Dipika Gaonkar Safis Editng Acquisition Editor Indexer Nikhil Karkal Hemangini Bari Content Development Editor Production Coordinator Sumeet Sawant Nitesh Thakur Technical Editor Cover Work Saurabh Malhotra Nitesh Thakur About the Author Achilleas Pipinellis is an open source enthusiast and tries to get involved in as many projects as possible.
    [Show full text]
  • Avaliação De Performance De Interpretadores Ruby
    Universidade Federal de Santa Catarina Centro Tecnológico Curso de Sistemas de Informação Wilson de Almeida Avaliação de Performance de Interpretadores Ruby Florianópolis 2010 Wilson de Almeida Avaliação de Performance de Interpretadores Ruby Monograa apresentada ao Curso de Sistemas de Informação da UFSC, como requisito para a obten- ção parcial do grau de BACHAREL em Sistemas de Informação. Orientador: Lúcia Helena Martins Pacheco Doutora em Engenharia Florianópolis 2010 Almeida, Wilson Avaliação de Performance de Interpretadores Ruby / Wilson Al- meida - 2010 xx.p 1.Performance 2. Interpretadores.. I.Título. CDU 536.21 Wilson de Almeida Avaliação de Performance de Interpretadores Ruby Monograa apresentada ao Curso de Sistemas de Informação da UFSC, como requisito para a obten- ção parcial do grau de BACHAREL em Sistemas de Informação. Aprovado em 21 de junho de 2010 BANCA EXAMINADORA Lúcia Helena Martins Pacheco Doutora em Engenharia José Eduardo De Lucca Mestre em Ciências da Computação Eduardo Bellani Bacharel em Sistemas de Informação Aos meus pais e meu irmão. Aos familiares e amigos, em especial pra mi- nha eterna amiga Liliana, que está torcendo por mim de onde ela estiver. Agradecimentos Agradeço ao meu amigo, colega de curso, parceiro de trabalhos e orientador Eduardo Bellani, pelo encorajamento, apoio e seus ricos conselhos sobre o melhor direci- onamento deste trabalho. A professora Lúcia Helena Martins Pacheco pela orientação, amizade, e pela paciência, sem a qual este trabalho não se realizaria. Ao professor José Eduardo Delucca, por seus conselhos objetivos e pontuais. Todos os meus amigos que incentivaram e compreenderam a minha ausência nesse período de corrida atrás do objetivo de concluir o curso.
    [Show full text]
  • Michael Johann Mjohann@Rails­Experts.Com
    Steinfurt, Germany Michael Johann mjohann@rails­experts.com http://www.rails­experts.com I am interested in new projects where various modern technologies are combined to build great innovative products. My view is from the full stack developer to architecture and engineering aspects. I am also passionate about being a CTO if the company is trusting my technical experience. I've supported the most known industry standards before thy became mainstream. I've founded JavaSPEKTRUM print magazine in 1996 and RailsWayMagazine (print) in 2009 and have been editor in chief for both magazines. In 2008 I wrote a german book about "JRuby on Rails for Java Enterprise Developers). As a regular speaker at conferences in Europe/USA, I always spread the news about new technologies and how they apply to projects. As a person with multiple interests I combine using technical aspects in development with writing and speaking at conferences. I've been an evangelist for Java and Rails. Technical Skills Like: ruby, on, rails, ios, android, java, jee, html5, css3, javascript, mongodb, torquebox, ansible, docker, rspec, cucumber Dislike: php, typo3, cobol Experience Chief Full Stack Developer – Smaps GmbH December 2013 ­ Current ruby­on­rails­4.1, objective­c, mongodb, android Responsible for product development of backend, frontend and mobile clients Backend consists of MongoDB Frontend is HTML5 with Bootstrap, JQuery, GoogleMaps API iOS Client native with RestKit API communication Android native (Java) Interims CTO – Eco Novum GmbH 2012 ­ November 2013 ios, mongodb, jrubyonrails, html5, css3, javascript, chef, git, jira, json Responsible for all architectural and technological aspects of the products (several mobile payment solutions).
    [Show full text]
  • Ruby on Rails™ Tutorial: Learn Web Developments with Rails
    ptg8286261 www.it-ebooks.info Praise for Michael Hartl’s Books and Videos on Ruby on RailsTM ‘‘My former company (CD Baby) was one of the first to loudly switch to Ruby on ptg8286261 Rails, and then even more loudly switch back to PHP (Google me to read about the drama). This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on RailsTM Tutorial is what I used to switch back to Rails again.’’ —From the Foreword by Derek Sivers (sivers.org) Formerly: Founder, CD Baby Currently: Founder, Thoughts Ltd. ‘‘Michael Hartl’s Rails Tutorial book is the #1 (and only, in my opinion) place to start when it comes to books about learning Rails. It’s an amazing piece of work and, unusually, walks you through building a Rails app from start to finish with testing. If you want to read just one book and feel like a Rails master by the end of it, pick the Ruby on RailsTM Tutorial.’’ —Peter Cooper Editor, Ruby Inside www.it-ebooks.info ‘‘Grounded in the real world.’’ —I Programmer (www.i-programmer.info), by Ian Elliot ‘‘The book gives you the theory and practice, while the videos focus on showing you in person how its done. Highly recommended combo.’’ —Antonio Cangiano, Software Engineer, IBM ‘‘The author is clearly an expert at the Ruby language and the Rails framework, but more than that, he is a working software engineer who introduces best practices throughout the text.’’ —Greg Charles, Senior Software Developer, Fairway Technologies ‘‘Overall, these video tutorials should be a great resource for anyone new to Rails.’’ —Michael Morin, ruby.about.com ‘‘Hands-down, I would recommend this book to anyone wanting to get into Ruby on Rails development.’’ —Michael Crump, Microsoft MVP ptg8286261 www.it-ebooks.info RUBY ON RAILSTM TUTORIAL Second Edition ptg8286261 www.it-ebooks.info Visit informit.com/ruby for a complete list of available products.
    [Show full text]
  • Deploying with Jruby Is the Definitive Text on Getting Jruby Applications up and Running
    Early Praise for Deploying JRuby Deploying with JRuby is the definitive text on getting JRuby applications up and running. Joe has pulled together a great collection of deployment knowledge, and the JRuby story is much stronger as a result. ➤ Charles Oliver Nutter JRuby Core team member and coauthor, Using JRuby Deploying with JRuby answers all of the most frequently asked questions regarding real-world use of JRuby that I have seen, including many we were not able to answer in Using JRuby. Whether you’re coming to JRuby from Ruby or Java, Joe fills in all the gaps you’ll need to deploy JRuby with confidence. ➤ Nick Sieger JRuby Core team member and coauthor, Using JRuby This book is an excellent guide to navigating the various JRuby deployment op- tions. Joe is fair in his assessment of these technologies and describes a clear path for getting your Ruby application up and running on the JVM. ➤ Bob McWhirter TorqueBox team lead at Red Hat Essential reading to learn not only how to deploy web applications on JRuby but also why. ➤ David Calavera Creator of Trinidad Deploying with JRuby is a must-read for anyone interested in production JRuby deployments. The book walks through the major deployment strategies by providing easy-to-follow examples that help the reader take full advantage of the JRuby servers while avoiding the common pitfalls of migrating an application to JRuby. ➤ Ben Browning TorqueBox developer at Red Hat Deploying with JRuby is an invaluable resource for anyone planning on using JRuby for web-based development. For those who have never used JRuby, Joe clearly presents its many advantages and few disadvantages in comparison to MRI.
    [Show full text]
  • High Availability Framework for Mix-Cloud Secure Applications
    PETR BELYAEV HIGH AVAILABILITY FRAMEWORK FOR MIX-CLOUD SE- CURE APPLICATIONS Master of Science thesis Examiners: Prof. Jose Luis Martinez Lastra, Dr. Andrei Lobov Examiners and topic approved by the Faculty Council of the Faculty of Automation and Science Engineering on 6th April 2016 i ABSTRACT PETR BELYAEV: High Availability Framework for Mix-Cloud Secure Applications Tampere University of Technology Master of Science thesis, 53 pages, 6 Appendix pages November 2016 Master's Degree Programme in Automation Technology Major: Factory Automation and Industrial Informatics Examiners: Prof. Jose Luis Martinez Lastra, Dr. Andrei Lobov Keywords: High Availability, clustering, cloud Having one of the services, such as web applications, databases or telephony systems, unavailable because of a single server failure is very annoying, yet very common issue, especially if the service is deployed on-premises. The simplest way to address it is to introduce redundancy to the system. But in this case the amount of physical machines needed will raise, while their eciency will drop as most of the services do not use 100% of machine's capabilities. The better way to solve the service availability issue is to logically separate the service from the underlying hardware, balancing the load between instances and migrating them between the physical machines in case of failure. This way is much more eective, but it also contains a number of challenges, such as conguration diculty and inter-service request routing. The High Availability (HA) framework discussed in this thesis was designed to miti- gate those issues. The key goal solved by the HA framework is raising the scalability and reliability of the service while keeping the conguration as simple as possible.
    [Show full text]
  • Ruby on Railsâ—¢ Tutorial
    www.it-ebooks.info Praise for Michael Hartl’s Books and Videos on Ruby on RailsTM ‘‘My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP (Google me to read about the drama). This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on RailsTM Tutorial is what I used to switch back to Rails again.’’ —From the Foreword by Derek Sivers (sivers.org) Formerly: Founder, CD Baby Currently: Founder, Thoughts Ltd. ‘‘Michael Hartl’s Rails Tutorial book is the #1 (and only, in my opinion) place to start when it comes to books about learning Rails. ... It’s an amazing piece of work and, unusually, walks you through building a Rails app from start to finish with testing. If you want to read just one book and feel like a Rails master by the end of it, pick the Ruby on RailsTM Tutorial.’’ —Peter Cooper Editor, Ruby Inside www.it-ebooks.info ‘‘Grounded in the real world.’’ —I Programmer (www.i-programmer.info), by Ian Elliot ‘‘The book gives you the theory and practice, while the videos focus on showing you in person how its done. Highly recommended combo.’’ —Antonio Cangiano, Software Engineer, IBM ‘‘The author is clearly an expert at the Ruby language and the Rails framework, but more than that, he is a working software engineer who introduces best practices throughout the text.’’ —Greg Charles, Senior Software Developer, Fairway Technologies ‘‘Overall, these video tutorials should be a great resource for anyone new to Rails.’’ —Michael Morin, ruby.about.com ‘‘Hands-down, I would recommend this book to anyone wanting to get into Ruby on Rails development.’’ —Michael Crump, Microsoft MVP www.it-ebooks.info RUBY ON RAILSTM TUTORIAL Second Edition www.it-ebooks.info Visit informit.com/ruby for a complete list of available products.
    [Show full text]
  • CSE341: Programming Languages Installing and Using Ruby and Irb Autumn 2018
    CSE341: Programming Languages Installing and Using Ruby and irb Autumn 2018 Contents 1 Overview ................................................. 1 2 Windows .................................................. 2 2.1 Using Windows in the Department's Undergraduate Labs . 2 2.2 Using the Department's Windows Machines Remotely . 2 2.3 Using Your Own Windows Machine . 2 3 Linux .................................................... 4 3.1 Using Linux in the Department's Undergraduate Labs . 4 3.2 Using Your Own Linux machine . 5 3.3 Using the Department's Remote Linux Server attu ....................... 5 3.4 Using the Department's Linux Virtual Machine on Your Machine . 5 4 Mac ..................................................... 6 4.1 Installation: Mac OS X Mojave, High Sierra, Sierra, and El Capitan . 6 4.2 Installation: Mac OS X Yosemite and Mavericks . 6 4.3 Installation: Mac OS X Mountain Lion and Older . 7 4.4 Editing and Running Code . 7 5 General Information on Using (or Not Using) the REPL ................... 7 6 Main Links for Ruby Documentation, etc. ............................ 7 1 Overview The last two homeworks will be using the Ruby language. We recommend editing your files in Emacs and using irb, which is Ruby's REPL. (If you prefer a different editor that has support for Ruby, that is fine.) This document describes basic installation and usage steps sufficient for doing your homework. Unlike when we used SML, we recommend running the REPL from a terminal (shell) window, not from within Emacs. This is described below. For installation purposes related to Homework 6, there are some key facts: • You need to have some version of Ruby 2, but in order to most easily use the Tk graphics library, which is necessary for Homework 6, we recommend Ruby 2.2.X for some X.
    [Show full text]
  • Introduction to Ruby on Rails
    Introduction to Ruby on Rails Thomas Kowark Software Engineering II Prof. Plattner, Dr. Uflacker WS 2015/16 Enterprise Platform and Integration Concepts group Introduction to Ruby on Rails 1. Ruby & Ruby on Rails ■ What is Ruby on Rails? ■ A few words about Ruby ■ Rails' core components ■ RESTful architecture 2. Your first Rails applicaon 3. Your introductory Rails exercise 4. AddiAonal Literature Introduction to Ruby on Rails — Software Engineering II — WS 2015/16 October 16, 2015 2 What is Ruby on Rails? Web applicaon development framework wriHen in Ruby ■ hHp://rubyonrails.org/ Philosophy ■ "Don't repeat yourself" – DRY ■ ConvenAon over Configuraon – there is "the Rails way" ■ RESTful architecture ■ Everything in its place Rails 1 Rails2 Rails 3 Rails 4 Rails 5 2003 2006 2009 2013 est. 2015 ■ Used by Github, Groupon, TwiHer (parAally) Introduction to Ruby on Rails — Software Engineering II — WS 2015/16 October 16, 2015 3 A few words about Ruby hHp://www.ruby-lang.org/ ■ Dynamic, reflecAve, general-purpose, object-oriented ■ Influenced by Perl, Smalltalk, Eiffel, and Lisp ■ Open-source, mature soaware ■ Matz’s Ruby Interpreter (MRI) versions: Yukihiro "Matz" Matsumoto with R. Stallman Ruby 1.0 Ruby 1.8.7 Ruby 1.9.3 Ruby 2.0.0 Ruby 2.2.2 1996 2010 2011 2013 2015 □ AddiAonally different VMs available (JRuby, Rubinius, IronRuby, Maglev) Introduction to Ruby on Rails — Software Engineering II — WS 2015/16 Image by Rubén Rodríguez (CC BY 3.0) - hHp://commons.wikimedia.org/wiki/File:Matz.jpgOctober 16, 2015 4 Rails Core Components Ac1on Pack Raili1es Ac1on View (core code, e.G.
    [Show full text]
  • Client-Server Web Apps with Javascript and Java
    Client-Server Web Apps with JavaScript and Java Casimir Saternos Client-Server Web Apps with JavaScript and Java by Casimir Saternos Copyright © 2014 EzGraphs, LLC. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editors: Simon St. Laurent and Allyson MacDonald Indexer: Judith McConville Production Editor: Kristen Brown Cover Designer: Karen Montgomery Copyeditor: Gillian McGarvey Interior Designer: David Futato Proofreader: Amanda Kersey Illustrator: Rebecca Demarest April 2014: First Edition Revision History for the First Edition: 2014-03-27: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449369330 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Client-Server Web Apps with JavaScript and Java, the image of a large Indian civet, and related trade dress are trademarks of O’Reilly Media, Inc. 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 O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
    [Show full text]
  • Rails Hosting 2012
    Rails Hosting 2012 1. Did you take the previous Rails hosting survey back in 2009? Response Response Percent Count Yes 23.2% 301 No 76.8% 997 answered question 1,298 skipped question 8 2. How many years have you been developing with Ruby on Rails? Response Response Percent Count Less than 1 year 11.0% 144 1-2 years 16.5% 215 2-3 years 17.4% 227 3-5 years 29.8% 388 More than 5 years 25.3% 330 answered question 1,304 skipped question 2 1 of 24 3. How many Ruby on Rails applications have you deployed? Response Response Percent Count None (yet) 1.6% 21 1 5.7% 74 2-5 41.1% 534 6-15 33.1% 429 15+ 18.5% 240 answered question 1,298 skipped question 8 4. How many Ruby (non-Rails, e.g., Sinatra) application have you deployed? Response Response Percent Count None (yet) 37.0% 480 1 13.9% 180 2-5 35.6% 462 6-15 8.2% 106 15+ 5.5% 71 answered question 1,299 skipped question 7 2 of 24 5. What versions of Ruby are you using in your applications? Response Response Percent Count Ruby 1.8.6 5.8% 75 Ruby 1.8.7 (REE or MRI) 52.9% 690 Ruby 1.9.2 47.9% 625 Ruby 1.9.3 78.4% 1,022 Rubinius 1.4% 18 JRuby 9.8% 128 answered question 1,304 skipped question 2 6. Are you using a Ruby version manager in production? Response Response Percent Count Yes 63.0% 818 No 37.0% 481 answered question 1,299 skipped question 7 3 of 24 7.
    [Show full text]
  • Ruby Version Manager for Windows « Ruby on Rails Outsourcing 6/7/2014
    Ruby version manager for Windows « Ruby on Rails Outsourcing 6/7/2014 Ruby version manager for Windows 28 Jul 2010 William Notowidagdo Knowledge Kiranatama Staff ruby, windows Tweet 1 Ruby version manager is a great tool that allows you to easily have multiple versions of Ruby. For Unix-based environment, there is RVM and for Windows we have Pik. This post will take you to have a quick look on Pik. Installation When writing this post I am using ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32] on Windows 7. You can use Pik from the Windows command line, Windows PowerShell, or Git Bash. Here I am using the command line. You can install pik via rubygems, or the Windows installer, or you can update pik with pik. Let us install pik using rubygems gem install pik If the installation gone smooth, you should see Successfully installed pik-0.2.8 1 gem installed After pik is installed now you want to use pik_install script to install the pik executable. You must install pik to a location in your path, but not in your Ruby bin directory. I add C:\bin to my path, so I run pik_install C:\bin then you should see pik is installed if you want to use pik with git bash, add the following line to your ~/.bashrc: [[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc Update: the command prompt from which you run pik has to be started using run as Administrator (if it’s Windows 7). Pik is modifying %PATH% environment variable and Windows 7 would silently not let it do so if not enough user privileges.
    [Show full text]