Ruby on Rails

“web development that doesn't hurt”
“Rails is the most well thought-out web
 development framework I’ve ever used.
  And that’s in a decade of doing web
appli...
“Ruby on Rails is a breakthrough in
  lowering the barriers of entry to
    programming. Powerful web
  applications that ...
“It is impossible not to notice Ruby
 on Rails. It has had a huge effect
    both in and outside the Ruby
 community... Ra...
“Ruby on Rails is astounding. Using it is
 like watching a kung-fu movie, where a
  dozen bad-ass frameworks prepare to
  ...
What is Ruby on Rails?
• Ruby is the language
• Rails is the framework
What is Ruby?
• created by Yukihiro Matsumoto (quot;Matzquot;)
  in 1993
• open source
• interpreted
• object-oriented (ev...
Hello Ruby!
puts “Hello Ruby!”
More about Ruby
•   not just for scripting
•   strives to be programmer friendly
•   is expressive, human readable
•   fol...
Ruby has…
•   dynamic typing (aka duck typing)
•   blocks (anonymous functions)
•   closures (like LISP)
•   “mix-in” modu...
Class Example
class Person
  attr_accessor :name
end
bob = Person.new
bob.name = “Bob the Builder”
Blocks & Iterators Example
tv_stars = [ bob, pat, maisy, sam ]
for character in tv_stars do
  puts character.name
end
tv_s...
Another Iterator Example
cool_stars = tv_stars.select { |character|
  character.name.include? “a”
}
Ranges Example
my_range = 1..10

my_range.each do |x|
 puts x
end
Hash Example
fav_machines = {
  “lofty” => 4, “muck” => 3,
           “scoop” => 8, “dizzy” => 0,
  “roley” => 5 }
fav_mac...
Open Class Example
class Fixnum
 def + (b)
   self - b
 end
end

1 + 1 equals 0?!
What is Rails?
• created by David Heinemeier Hansson
  (quot;DHHquot;) of 37 Signals in 2004
• open source
• a web framewo...
Hello Rails!
class HelloController < ApplicationController
 def index
   @greeting = quot;Hello Rails!”
 end
end

<h1><%= ...
More about Rails
•   it is “opinionated” software
•   uses convention over configuration
•   uses the Model-View-Controlle...
Rails Supports…
• BDD, TDD and automated testing
• AJAX and web services: SOAP, XML-RPC,
  REST
• meta-programming and dom...
Active Record
•   ORM layer supplied with Rails
•   tables map to classes
•   rows to objects
•   columns to object attrib...
Active Record Example
class Order < ActiveRecord::Base
end
order = Order.find(1)
order.discount = 0.5
order.save
Relationship Example
class Person < ActiveRecord::Base
end
class Event < ActiveRecord::Base
 has_and_belongs_to_many :part...
Better Example
class Project < ActiveRecord::Base
   belongs_to :portfolio
   has_one :project_manager
   has_many :milest...
Migration Example
create_table :people do |table|
 table.column :first_name,     :string
 table.column :last_name,      :s...
BDD Example (RSpec)
describe User do
 it quot;should be invalid without a usernamequot; do
   @user.attributes = valid_use...
Demos
Demos
Links
•   Ruby on Rails, rubyonrails.com
•   Ruby, ruby-lang.org
•   Agile Web Development with Rails, pragprog.com
•   Ra...
Ruby on Rails Presentation
Upcoming SlideShare
Loading in...5
×

Ruby on Rails Presentation

1,116

Published on

An overview of Ruby on Rails for web developers

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,116
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby on Rails Presentation

  1. 1. Ruby on Rails “web development that doesn't hurt”
  2. 2. “Rails is the most well thought-out web development framework I’ve ever used. And that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” James Duncan Davidson, Creator of Tomcat and Ant
  3. 3. “Ruby on Rails is a breakthrough in lowering the barriers of entry to programming. Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days.” Tim O'Reilly, Founder of O'Reilly Media
  4. 4. “It is impossible not to notice Ruby on Rails. It has had a huge effect both in and outside the Ruby community... Rails has become a standard to which even well- established tools are comparing themselves to.” Martin Fowler, Author of Refactoring, PoEAA, XP Explained
  5. 5. “Ruby on Rails is astounding. Using it is like watching a kung-fu movie, where a dozen bad-ass frameworks prepare to beat up the little newcomer only to be handed their asses in a variety of imaginative ways.” Nathan Torkington, O'Reilly Program Chair for OSCON
  6. 6. What is Ruby on Rails? • Ruby is the language • Rails is the framework
  7. 7. What is Ruby? • created by Yukihiro Matsumoto (quot;Matzquot;) in 1993 • open source • interpreted • object-oriented (everything is an object) • combines syntax inspired by Perl with Smalltalk-like features
  8. 8. Hello Ruby! puts “Hello Ruby!”
  9. 9. More about Ruby • not just for scripting • strives to be programmer friendly • is expressive, human readable • follows the principle of least surprise
  10. 10. Ruby has… • dynamic typing (aka duck typing) • blocks (anonymous functions) • closures (like LISP) • “mix-in” modules (multiple inheritance) • operator overloading • open classes
  11. 11. Class Example class Person attr_accessor :name end bob = Person.new bob.name = “Bob the Builder”
  12. 12. Blocks & Iterators Example tv_stars = [ bob, pat, maisy, sam ] for character in tv_stars do puts character.name end tv_stars.each { | character | puts character.name }
  13. 13. Another Iterator Example cool_stars = tv_stars.select { |character| character.name.include? “a” }
  14. 14. Ranges Example my_range = 1..10 my_range.each do |x| puts x end
  15. 15. Hash Example fav_machines = { “lofty” => 4, “muck” => 3, “scoop” => 8, “dizzy” => 0, “roley” => 5 } fav_machines[“scoop”] »8 fav_machines[“lofty”] += 1 »5 fav_machines[“scrambler”] = 6
  16. 16. Open Class Example class Fixnum def + (b) self - b end end 1 + 1 equals 0?!
  17. 17. What is Rails? • created by David Heinemeier Hansson (quot;DHHquot;) of 37 Signals in 2004 • open source • a web framework that is optimized for programmer happiness • designed for developing database-backed web applications • designed for agile development
  18. 18. Hello Rails! class HelloController < ApplicationController def index @greeting = quot;Hello Rails!” end end <h1><%= @greeting %></h1>
  19. 19. More about Rails • it is “opinionated” software • uses convention over configuration • uses the Model-View-Controller pattern • focuses on CRUD • uses object relational mapping • follows principle of DRY (don’t repeat yourself)
  20. 20. Rails Supports… • BDD, TDD and automated testing • AJAX and web services: SOAP, XML-RPC, REST • meta-programming and domain specific languages • variety of databases: MySQL, PostgreSQL, SQLite, Oracle, SQL Server, DB2 etc • variety of web servers: Apache, lighttpd, nginx, Mongrel etc • most platforms: Windows, Mac, Linux
  21. 21. Active Record • ORM layer supplied with Rails • tables map to classes • rows to objects • columns to object attributes • uses conventions to minimise configuration
  22. 22. Active Record Example class Order < ActiveRecord::Base end order = Order.find(1) order.discount = 0.5 order.save
  23. 23. Relationship Example class Person < ActiveRecord::Base end class Event < ActiveRecord::Base has_and_belongs_to_many :participants, :class_name => quot;Personquot; end party_people = Event.find(1).participants
  24. 24. Better Example class Project < ActiveRecord::Base belongs_to :portfolio has_one :project_manager has_many :milestones has_many :deliverables, :through => :milestones validates_presence_of :name, :description validates_acceptance_of :non_disclosure_agreement validates_uniqueness_of :short_name end
  25. 25. Migration Example create_table :people do |table| table.column :first_name, :string table.column :last_name, :string table.column :age, :integer end
  26. 26. BDD Example (RSpec) describe User do it quot;should be invalid without a usernamequot; do @user.attributes = valid_user_attributes.except(:username) @user.should_not_be_valid @user.errors.on(:username).should_equal quot;is requiredquot; @user.username = 'someusername' @user.should_be_valid end it “should be invalid without an emailquot; it quot;should be invalid without a password” end
  27. 27. Demos
  28. 28. Demos
  29. 29. Links • Ruby on Rails, rubyonrails.com • Ruby, ruby-lang.org • Agile Web Development with Rails, pragprog.com • RailsCasts, railscasts.com • Ruby on Rails Oceania, rubyonrails.com.au • Canberra Ruby Crew, canberraruby.com • Mike Williams, dogbiscuit.org/mdub/presentations/ Ruby@EJA (for some of the presentation material)

×