intro for ror
DESCRIPTION
Introduction For Ruby On RailsTRANSCRIPT
![Page 1: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/1.jpg)
An Introduction to Ruby and Rails
Matthew BohnsackWannabe RubyistNovember 9th 2005
![Page 2: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/2.jpg)
November 9th 2005 2An Introduction to Ruby and Rails
Outline
What is Ruby and why should I care? What is Rails and why should I care? Two must-have tools for Ruby development Major Ruby features (the language in a nutshell) Rails overview Where to go for more information Questions / Hacking
![Page 3: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/3.jpg)
November 9th 2005 3An Introduction to Ruby and Rails
What is Ruby? Why should I care?
What: The Wikipedia answer is here. Created/lead by Matz (Japanese) Open Source interpreted scripting language, like Perl, Python,
Tcl, etc., but focused on being very object oriented, expressive, and bringing joy to programming.
Principle of least surprise Why:
Productivity ideas presented in Ousterhout’s 1998 paper coming to very serious critical mass (and beyond)
Learn a new language to learn new ways of thinking about code in any language (e.g., blocks and iterators)
Joy!
![Page 4: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/4.jpg)
November 9th 2005 4An Introduction to Ruby and Rails
What is Rails? Why should I care?
What: Web Framework that makes building database-driven MVC-oriented web apps
easy through a template engine, ORM (ActiveRecord) and other best practices, such as test driven development, deployment tools, patterns, etc.
Much less complicated than J2EE solutions, but perhaps more so than PHP or Perl in cgi-bin.
Copy cats are being created in other languages: Python (TurboGears) Perl (Maypole)
http://rubyonrails.org/ + book + online screencasts + online docs & tutorials Why:
I’ve been watching the world of web development since ~ 1995, and I’ve never seen anything like Rails in terms of buzz, momentum, adoption rate, etc.
![Page 5: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/5.jpg)
November 9th 2005 5An Introduction to Ruby and Rails
Must have tool #1: irb
Interactive ruby console:Experiment on the flyTab complete object methods…
# ~/.irbrc
require 'irb/completion'
use_readline=true
auto_indent_mode=true
![Page 6: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/6.jpg)
November 9th 2005 6An Introduction to Ruby and Rails
Must have tool #2: ri
Console-based Ruby doc tool
![Page 7: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/7.jpg)
November 9th 2005 7An Introduction to Ruby and Rails
Ruby in a nutshell – irb sessions follow Like all interpreted scripting languages, you can
put code into a file, chmod +x, then just execute it.
But, we’ll mostly use irb sessions in this presentation…
![Page 8: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/8.jpg)
November 9th 2005 8An Introduction to Ruby and Rails
Ruby in a nutshell – objects are everywhere Some languages have built-in types that aren’t
objects. Not so with Ruby. Everything’s an object:
![Page 9: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/9.jpg)
November 9th 2005 9An Introduction to Ruby and Rails
Ruby in a nutshell – objects have methods
Bang on the tab key in irb to see the methods that are available for each object.
![Page 10: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/10.jpg)
November 9th 2005 10An Introduction to Ruby and Rails
Ruby in a nutshell – Variables Local variables - start with lower case:
foo bar
Global variables - start with dollar sign: $foo $bar
Constants and Classes – start with capital letter: CONSTANT Class
Instance variables – start with at sign: @foo @bar
Class variables – start with double at sign: @@foo @@bar
![Page 11: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/11.jpg)
November 9th 2005 11An Introduction to Ruby and Rails
Ruby in a nutshell – Arrays
![Page 12: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/12.jpg)
November 9th 2005 12An Introduction to Ruby and Rails
Ruby in a nutshell – Hashes
![Page 13: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/13.jpg)
November 9th 2005 13An Introduction to Ruby and Rails
Ruby in a nutshell – Symbols Starts with a ‘:’ Only one copy of a symbol kept in memory
![Page 14: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/14.jpg)
November 9th 2005 14An Introduction to Ruby and Rails
Ruby in a nutshell – Blocks & Iterators
![Page 15: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/15.jpg)
November 9th 2005 15An Introduction to Ruby and Rails
Ruby in a nutshell – It’s easy to build classes
![Page 16: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/16.jpg)
November 9th 2005 16An Introduction to Ruby and Rails
Ruby in a nutshell – It’s fun to play with classes (like the one we just made)
![Page 17: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/17.jpg)
November 9th 2005 17An Introduction to Ruby and Rails
Ruby in a nutshell – Classes are open
Example shown here uses our Hacker class, but what happens when the whole language is open?
![Page 18: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/18.jpg)
November 9th 2005 18An Introduction to Ruby and Rails
Ruby in a nutshell – Other notes on Classes Ruby only has single inheritance. This
makes things simpler, but mix-ins provide much of multiple inheritance’s benefit, without the hassle.
![Page 19: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/19.jpg)
November 9th 2005 19An Introduction to Ruby and Rails
Ruby in a nutshell – a few gotchas
Despite the principle of least surprise: Zero isn’t false:
No increment operator (foo++). Instead use: foo += 1 foo = foo + 1
![Page 20: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/20.jpg)
November 9th 2005 20An Introduction to Ruby and Rails
Ruby in a nutshell – RubyGems
CPAN for Ruby? http://docs.rubygems.org/ Examples:
gem list
gem install redcloth --version ">= 3.0.0" …
Using gems in your program: require ‘rubygems’ require ‘some_gem’
![Page 21: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/21.jpg)
November 9th 2005 21An Introduction to Ruby and Rails
Want to learn more Ruby? Excellent, simple, beginner’s tutorial:
http://www.math.umd.edu/~dcarrera/ruby/0.3/index.html Other stuff at end of talk Start hacking
![Page 22: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/22.jpg)
November 9th 2005 22An Introduction to Ruby and Rails
Quick Rails Demo – Build a TODO list application in 5 minutes Define database rails todo cd todo Edit config/database.yml ./script/generate model Todo ./script/generate scaffold todo Look at scaffolding ./script/server –b www.bohnsack.com Add due_date field, regenerate scaffolding, and check the results ./script/console
![Page 23: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/23.jpg)
November 9th 2005 23An Introduction to Ruby and Rails
Where to go for more information Books:
Online material: First edition of Pickaxe online for free http://www.ruby-doc.org/ why’s (poignant) guide to Ruby http://rubyonrails.org/ Rails screencast(s) Planet Ruby on Rails
![Page 24: Intro for RoR](https://reader035.vdocuments.site/reader035/viewer/2022081512/55519a33b4c9053c488b46ba/html5/thumbnails/24.jpg)
November 9th 2005 24An Introduction to Ruby and Rails
The End / Questions