Transcript Document

Ruby on Rails
8th February 2007
Bill Malkin
Ruby on Rails
Why does RoR interest us?
•
•
•
•
Learn “new” concepts and terms.
Look at “new” architecture.
Find out what is good and what is dubious.
May well come across RoR or a Rails-like framework
in near future.
• May want to learn an object-oriented language
relatively painlessly.
• RoR is easy to install, learn and use. You might want
to try it out for yourself!
8th February 2007
Bill Malkin
Ruby on Rails
Executive Summary
•
•
•
•
•
•
•
•
•
•
A lot of hype (many evangelists)
Some dubious claims
Some very good, new concepts
Some old concepts with new names
Ruby camp - humble
Rails camp - arrogant
Still missing some essential tools
Rails techniques can certainly be applied elsewhere
Surprisingly large tools and software base
But Ruby and Rails are each very powerful in their own right
8th February 2007
Bill Malkin
Ruby on Rails
At First Sight
• Can only be used for web-based, specifically HTMLbased, applications
• Designed for small to medium CRUD-based
applications
• Cross-platform
• Can use same tools and middleware on Windows,
Linux and OS X.
• Easy-install packages for Eclipse (with RADRails and
Ruby editor plugins), MySQL, Apache, and other
Eclipse plugins, eg Subversion.
8th February 2007
Bill Malkin
Ruby on Rails
Books
• Beyond Java - Bruce Tate (evangelist)
• Programming Ruby (The Pragmatic
Programmers’ Guide) - Dave Thomas
• Ruby Cookbook - Carlson & Richardson
Agile Web Development with Rails (Pragmatic
Programmers) - Thomas, Hansson, Breedt and
Clark
• Rails Recipes - Chad Fowler
Ruby on Rails (Up and Running) - Tate & Gibbs
[160 pages]
8th February 2007
Bill Malkin
Ruby on Rails
Other References
• Ruby home page
http://www.ruby-lang.org/en/
• Ruby Central
http://www.rubycentral.com/
• Rails home page
http://www.rubyonrails.org/
• Wikipedia entries on Ruby and Ruby on Rails
8th February 2007
Bill Malkin
Ruby on Rails
Available Information
8th February 2007
Bill Malkin
Ruby on Rails
History of Ruby
• 1993, Feb 24: Yukihiro Matsumoto ("Matz")
started work on Ruby
• 1993, Summer: First "Hello, world!" program
• 1995, December: First release 0.95
• 1996, December: 1.0 is released
• 1999: Supposedly overtakes Python in Japan
• 2000: The first official newsgroup
• 2000-2001: Several books published
• 2003, August 4: 1.8.0 is released
8th February 2007
Bill Malkin
Ruby on Rails
History of Rails
• Developed by David Heinemeier Hansson as
part of an application called Basecamp.
• 2004, July: Released the framework as open
source
• 2005, Feb: Shared the commit rights
• 2005, Dec: Version 1.0 released
• 2006, Mar: Version 1.1 released
• 2007, Jan: Version 1.2 released
8th February 2007
Bill Malkin
Ruby on Rails
A Ruby Example
class Account
attr_reader :balance
#accessor
protected :balance
def initialize(balance)
@balance = balance
end
def greater_balance_than(other)
return @balance > other.balance
end
end
8th February 2007
Bill Malkin
A Peak at Rails
Ruby on Rails
.
8th February 2007
Bill Malkin
Ruby on Rails
Basics
•
•
•
•
•
•
Ruby - fully object oriented
Rails - full stack framework (sort of)
ActionView, ActionController, ActiveRecord
AJAX using script.aculo.us JavaScript libraries
Uses rake (like make or Ant)
Can use an interpreter to try out Ruby
commands
8th February 2007
Bill Malkin
Ruby on Rails
Request Flow
Ruby on Rails
8th February 2007
Bill Malkin
Ruby on Rails
Terms and Concepts
•
•
•
•
•
•
•
Duck Typing
DRY (Don’t Repeat Yourself)
MVC (Model-View-Controller)
Model2 - stateless web apps
Metaprogramming
Convention Over Configuration
Scaffolding
8th February 2007
Bill Malkin
Ruby on Rails
Deployment Environments
•
•
•
•
Development, Test and Production
Each has its own, default runtime settings
One database for each
Schema Migrations
–
–
–
–
–
–
Manages the schemas and any changes
Keeps track of a list of migrations
Each migration has version number
Can modify schema without losing data
Can migrate schema through test and production
Can make or undo the schema change
8th February 2007
Bill Malkin
Ruby on Rails
Automated Testing
• RoR generates default test cases to test each method
in each class
• Uses assertions to test results against expected
values
• Test data refreshed on start of test
• Fixtures - contain your test data
• Unit Tests - for testing models
• Functional Tests - for testing controllers
• Integration Tests - for higher level scenarios
• Functional and Integration Tests check Http responses
• ZenTest and Selenium
8th February 2007
Bill Malkin
Ruby on Rails
Configuration
• Uses Convention over Configuration, and Reflection
• Therefore very little configuration compared to other
frameworks
• ActiveRecord configuration can use SQL
• Uses YAML (easy to read) rather than XML
development:
adapter: oci
host: 192.168.0.50/examplesid
username: exampleuser
password: examplepass
8th February 2007
Bill Malkin
Ruby on Rails
Web 2.0 Features
from wikipedia
• Rich Internet application techniques, optionally Ajaxbased
• CSS
• XHTML markup and Microformats
• RSS/Atom
• Clean and meaningful URLs
• Folksonomies (in the form of tags or tagclouds for
example)
• Wikis, Weblogs, Mashups
• REST or XML Webservice APIs
8th February 2007
Bill Malkin
Ruby on Rails
Other Rails-Like Frameworks
•
•
•
•
•
Groovy: Groovy on Rails -> Grails
Java: Trails
PHP: PHP on Rails -> PHP on TRAX
ASP.NET: Monorail (Beta 4)
Python: TurboGears (well, sort of)
This is another language/framework to watch out for.
8th February 2007
Bill Malkin
Ruby on Rails
Disadvantages
• No big corporate backer
• Very few expert Ruby programmers, and universities
and TAFEs have not picked it up
• Runs slowly (Java ~ 5 times faster but Ruby may be
improved by new VM - YARV)
• Poor editor support and very slow debugger
• No clustering, failover
• No two-phase commit
• Does not support compound primary keys
• Internationalization support is weak
• No off-the-shelf reporting tool
8th February 2007
Bill Malkin
Ruby on Rails
•
•
•
•
•
•
•
•
Advantages
Standard directory structure for source
Can build prototype very quickly
Can add to and change prototype easily
Can generate scaffolding, if app is more complex, and
build on this
Very powerful, high-level commands
Ruby has great short-hand code for common patterns,
eg the Value Object
Built in testing, migration, and some version control
Does not constrain the programmer like other
frameworks
8th February 2007
Bill Malkin
Ruby on Rails
Positive Signs
• Ruby declared TIOBE's Programming Language of the
Year, 2006 (10th)
• Agile Web Development with Rails - No 3 in Amazon’s
Best Books (Computers and Internet) 2006
• JRuby - Ruby on JVM, being developed by SUN
• Mac OS X 10.5 (Leopard) will have Ruby and RoR
pre-installed
• IBM offers a Starter Toolkit for DB2 on Rails
• Oracle have tutorials and a FAQ on RoR
8th February 2007
Bill Malkin
Ruby on Rails
Defections from Java to Ruby
•
•
•
•
•
•
•
•
James Duncan Davidson (ANT)
Mike Clark (Pragmatic Automation)
Jason Hunter (Java Servlet Programming)
Bruce Tate (Bitter Java, Spring Dev Notebook)
Dion Almaer (Founder of theserverside.com)
Stuart Holloway (Component Dev for Java)
Justin Gehtland (Better, Faster, Lighter Java)
Glenn Vanderburg (Tricks of the Java Programming
Gurus)
• David Geary (Graphic Java, Core JSF)
8th February 2007
Bill Malkin
Ruby on Rails
Trivia
• Ruby was named after the birthstone of
a colleague of Matz (birthstone of July)
• Pearl (Perl) is the birthstone of June
8th February 2007
Bill Malkin
Ruby on Rails
RoR in Baby Steps
1. Read the Wikipedia entries on Ruby and
Ruby on Rails
2. Read the Ruby / Ruby on Rails Cheat Sheet
http://www.blainekendall.com/uploads/RubyOnRailsCheatsheet-BlaineKendall.pdf
3. Follow instructions to install tools and web
server
http://ruby.meetup.com/73/boards/view/viewthread?t
hread=2203432
4. Read the book to develop your first app!
Ruby on Rails, Up and Running
8th February 2007
Bill Malkin
Ruby on Rails
Conclusions
• Can only be used for web-based, specifically HTML-based,
applications
• Designed for small to medium CRUD-based applications
• Cross-platform
• A lot of hype (many evangelists)
• Some dubious claims, very little expertise
• Some very good, new concepts, some old with new names
• Still missing some essential tools
• Rails-type framework can certainly be applied elsewhere
• Surprisingly large tools and software base
• Ruby and Rails are each very powerful in their own right
• Looks good!
8th February 2007
Bill Malkin