Ruby on Rails
An Introduction
Mark S. Maglana, CompE, MM
Let's get this out of the way...
ยป My name is Mark S. Maglana
ยป Bachelor's Degree in Computer Engineering from
the University of San Carlos, Cebu
ยป Master in Management from the University of the
Philippines in Mindanao
ยป Computer geek since grade 5 (BASIC, QBASIC)
ยป Suffered through C, assembly in college
ยป Web dude since 1997, started with ASP 1.0
ยป ASP.Net, PHP (w/ CakePHP)
ยป UML, VB, .Net, C#, Java, Lotus Notes/Domino
โ€œI constantly remind myself that there are multiple
ways and numerous technologies [for] solving a
single problem, some better than others.โ€
โ€œBy being loyal to one technology stack, I am bound
to unconsciously make biased decisions, which will
ultimately hinder my ability to deliver business
value.โ€
- Stephen Chu
http://tinyurl.com/zz995
Ruby on Rails
A Programming
Language
A Web Framework
built w/ Ruby
Hold it right there, sparky...
This is an introduction, not a tutorial
We wont get in-depth with Ruby and Rails
(You're too intelligent to be spoon fed)
I assume you're familiar with OOP
Ruby
ยป Created by Yukihiro โ€œMatzโ€ Matsumoto in 1993
ยป A language designed for humans, not compilers
ยป A true Object-Oriented language
ยป Everything you manipulate in Ruby is an object
ยป They all ultimately inherit from a class named
Object (Surprise! Surprise!)
ยป Because everything is an object, there's none of
that primitive types vs. reference types silliness.
Hello World
# The famous Hello World
# program is trivial in
# Ruby. You don't need:
#
# * a "main" method
# * newline escapes
# * semicolons
#
# Here's the code:
puts "Hello World!"
Ruby won't force you to define a class if you don't
need to. In such a case, Ruby automatically
encloses your statement in an Object instance.
Other Examples
door.close if door.is_open?
5.times { puts โ€œOdelay!โ€ }
my_text = 'restaurant'
exit unless my_text.include? 'rant'
animals = ['cat', 'dog', 'fox']
animals.each {|animal| puts animal.capitalize}
small_number = 1212123
really_big_number = 1412432423429340234581340234
pretty_number = 12_000_000_000
And here's one more...
class Person
attr_accessor :name, :age, :sex
end
person = Person.new
person.name = 'Perting E. Soga'
person.age = 36
person.sex = 'M'
puts person.name # Perting E. Soga
puts person.age # 36
puts person.sex # M
Ruby Conventions
ยป Variables starting with $ are Global Variables
(ex. $x, $1, $chunky_bacon)
ยป Variables starting with @ are Instance Variables
(ex. @width, @x, @y)
ยป Variables starting with @@ are Class Variables
(ex. @@brokeback_coding, @@choo_choo)
ยป Variables without prefixes are Local Variables
(ex. chicken_noodles, white_flower)
ยป Constants are always capitalized
(ex. Time, Array, LuckyPenguin)
Rails
ยป Created by David Heinemeier Hansson in 2003
ยป A web application framework built using Ruby
ยป Uses the Model-View-Controller (MVC) design
pattern
ยป Also uses the ActiveRecord design pattern
ยป Some ex-Java programmers claim Rails helped
them develop applications 10x faster
Show me the money!
code
How Rails Works
Internet Web Server
controller
database
view
/posts/show/1
posts_controller.rb
model
post.rb
show.rhtml
blog_production
PostsController::show()
Post::find(1)
1.
2.
3.
4.
5.
6.
7.
8.
9.
Recommended Set-up
Internet Apache 2.2+
MongrelMongrel Mongrel
database
mod_proxy
mod_proxy_balancer
HTTP
HTTP HTTP HTTP
Additional Reading
ยป www.ruby-lang.org
ยป www.rubyonrails.org
ยป http://pine.fm/LearnToProgram/
ยป ruby-phil@googlegroups.com
ยป Google for โ€œOnLAMP Rolling with Railsโ€
ยป #rubyonrails and #ruby-lang in IRC (freenode)
ยป wiki.rubyonrails.org
ยป api.rubyonrails.org
ยป Agile Web Development book
ยป Programming Ruby book
And we're done!

Slides

  • 1.
    Ruby on Rails AnIntroduction Mark S. Maglana, CompE, MM
  • 2.
    Let's get thisout of the way... ยป My name is Mark S. Maglana ยป Bachelor's Degree in Computer Engineering from the University of San Carlos, Cebu ยป Master in Management from the University of the Philippines in Mindanao ยป Computer geek since grade 5 (BASIC, QBASIC) ยป Suffered through C, assembly in college ยป Web dude since 1997, started with ASP 1.0 ยป ASP.Net, PHP (w/ CakePHP) ยป UML, VB, .Net, C#, Java, Lotus Notes/Domino
  • 3.
    โ€œI constantly remindmyself that there are multiple ways and numerous technologies [for] solving a single problem, some better than others.โ€ โ€œBy being loyal to one technology stack, I am bound to unconsciously make biased decisions, which will ultimately hinder my ability to deliver business value.โ€ - Stephen Chu http://tinyurl.com/zz995
  • 4.
    Ruby on Rails AProgramming Language A Web Framework built w/ Ruby
  • 5.
    Hold it rightthere, sparky...
  • 6.
    This is anintroduction, not a tutorial We wont get in-depth with Ruby and Rails (You're too intelligent to be spoon fed) I assume you're familiar with OOP
  • 7.
    Ruby ยป Created byYukihiro โ€œMatzโ€ Matsumoto in 1993 ยป A language designed for humans, not compilers ยป A true Object-Oriented language ยป Everything you manipulate in Ruby is an object ยป They all ultimately inherit from a class named Object (Surprise! Surprise!) ยป Because everything is an object, there's none of that primitive types vs. reference types silliness.
  • 8.
    Hello World # Thefamous Hello World # program is trivial in # Ruby. You don't need: # # * a "main" method # * newline escapes # * semicolons # # Here's the code: puts "Hello World!" Ruby won't force you to define a class if you don't need to. In such a case, Ruby automatically encloses your statement in an Object instance.
  • 9.
    Other Examples door.close ifdoor.is_open? 5.times { puts โ€œOdelay!โ€ } my_text = 'restaurant' exit unless my_text.include? 'rant' animals = ['cat', 'dog', 'fox'] animals.each {|animal| puts animal.capitalize} small_number = 1212123 really_big_number = 1412432423429340234581340234 pretty_number = 12_000_000_000
  • 10.
    And here's onemore... class Person attr_accessor :name, :age, :sex end person = Person.new person.name = 'Perting E. Soga' person.age = 36 person.sex = 'M' puts person.name # Perting E. Soga puts person.age # 36 puts person.sex # M
  • 11.
    Ruby Conventions ยป Variablesstarting with $ are Global Variables (ex. $x, $1, $chunky_bacon) ยป Variables starting with @ are Instance Variables (ex. @width, @x, @y) ยป Variables starting with @@ are Class Variables (ex. @@brokeback_coding, @@choo_choo) ยป Variables without prefixes are Local Variables (ex. chicken_noodles, white_flower) ยป Constants are always capitalized (ex. Time, Array, LuckyPenguin)
  • 12.
    Rails ยป Created byDavid Heinemeier Hansson in 2003 ยป A web application framework built using Ruby ยป Uses the Model-View-Controller (MVC) design pattern ยป Also uses the ActiveRecord design pattern ยป Some ex-Java programmers claim Rails helped them develop applications 10x faster
  • 13.
    Show me themoney! code
  • 14.
    How Rails Works InternetWeb Server controller database view /posts/show/1 posts_controller.rb model post.rb show.rhtml blog_production PostsController::show() Post::find(1) 1. 2. 3. 4. 5. 6. 7. 8. 9.
  • 15.
    Recommended Set-up Internet Apache2.2+ MongrelMongrel Mongrel database mod_proxy mod_proxy_balancer HTTP HTTP HTTP HTTP
  • 16.
    Additional Reading ยป www.ruby-lang.org ยปwww.rubyonrails.org ยป http://pine.fm/LearnToProgram/ ยป ruby-phil@googlegroups.com ยป Google for โ€œOnLAMP Rolling with Railsโ€ ยป #rubyonrails and #ruby-lang in IRC (freenode) ยป wiki.rubyonrails.org ยป api.rubyonrails.org ยป Agile Web Development book ยป Programming Ruby book
  • 17.