RUBY ON RAILS
Introduction to Ruby
What is Ruby?
Ruby is:
from Japan
from Japan
Yukihiro “Matz” Matsumoto
Ruby is:
a scripting language
a scripting language
“Ruby is simple in appearance, but is very complex
inside, just like ou...
Ruby is:
Object Oriented
Object Oriented
“I wanted a scripting language that was more powerful
than Perl, and more object-...
Ruby is:
Flexible
Flexible
class Numeric
def plus(x)
self.+(x)
end
end
y = 5.plus 6
# y is now equal to 11
Ruby has:
Blocks
Blockssearch_engines =
%w[Google Yahoo MSN].map do |engine|
"http://www." + engine.downcase + ".com"
end
...
Ruby is:
Single Inheritance
Single Inheritance
class MyArray
include Enumerable
end
Ruby is:
Pretty Easy to Read
Pretty Easy to Read
var could be a local variable.
@var is an instance variable.
$var is a gl...
What is Rails?
Rails is:
A Web Application Framework
written in Ruby
What’s the advantage?
Functionality common to many web applications
abstracted into a stable, tested code base.
Rails leve...
So why is Rails unique?
Convention Over Configuration approach to get you
started quickly.
DRY principles and built-in tes...
How easy is it, really?
Let’s do an example.
How is it Structured?
Model View Controller
Model=State, View=Response to User,
Controller=Logic
How does that show
up in Rails?
Model — ActiveRecord
Controller—ActionController
View—ActionView
MVC in Webapps
Model
OO abstraction for RDB
Classes—Tables
Objects—Rows
Queries & Operations—Class Methods
class Client < ActiveRecord::B...
View
Templates for HTML documents
ERB—Embedded Ruby
Controller
Interface between user, model and view.
This is where you line everything up.
Let’s go back to the
example
Assignment
“Seems really pricey for a relatively simple software like
this. Someone write an opensource alternative? it lo...
Rewrite Stack
Overflow
Requirements: Questions, Responses, Users, Voting
Go further if you feel ambitious.
Tools Required
Text editor,
Terminal,
script/server,
http://api.rubyonrails.org/,
http://www.ruby-doc.org/core/,
http://gu...
Upcoming SlideShare
Loading in …5
×

Slides - WordPress.com — Get a Free Blog Here

1,053 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,053
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • “Since its public release in 1995, Ruby has drawn devoted coders worldwide.”
    “Its creator, Yukihiro “Matz” Matsumoto, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.” - ruby-lang.org
    Imperative programming
    From Wikipedia, the free encyclopedia
    In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state. In much the same way that imperative mood in natural languages expresses commands to take action, imperative programs define sequences of commands for the computer to perform.
    Functional programming
    From Wikipedia, the free encyclopedia
    In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state.
  • “The TIOBE index, which measures the growth of programming languages, ranks Ruby as #9 among programming languages worldwide. Much of the growth is attributed to the popularity of software written in Ruby, particularly the Ruby on Rails web framework.” — ruby-lang.org
  • “In many languages, numbers and other primitive types are not objects.
    Ruby follows the influence of the Smalltalk language by giving methods and instance variables to all of its types.
    This eases one’s use of Ruby, since rules applying to objects apply to all of Ruby.”
    Quote and example from http://ruby-lang.org/en/about
  • “For example, addition is performed with the plus (+) operator. But, if you’d rather use the readable word plus, you could add such a method to Ruby’s builtin Numeric class.”
    — http://ruby-lang.org/en/about
  • Blocks are inspired by functional languages. Matz said, “in Ruby closures, I wanted to respect the Lisp culture.” — quote and example, http://ruby-lang.org/en/about
  • Instead, you can “mixin” with modules.
    Example from — http://ruby-lang.org/en/about
  • Example from — http://ruby-lang.org/en/about
  • Rails leverages the RubyGem code packaging system to make installing and versioning libraries of code exceedingly easy. “Ruby on Rails” is really 6 different RubyGems:
    actionmailer (2.3.4)actionpack (2.3.4)activerecord (2.3.4)activeresource (2.3.4)activesupport (2.3.4)
    railties
  • In reality, this approach has been used before and since. All the elements in Rails have been used in other frameworks. It’s just a matter of preference for the Rails Way. It also helps that there is such a large and active user base.
  • cd projects
    rails -d mysql blog-for-rails-course
    cd blog-for-rails-course
    ls script
    script/server
    [check the new server]
    script/generate scaffold Post title:string body:text
    [check back to localhost:3000/posts] whoops!
    rake db:create
    rake db:migrate
    [check back to localhost:3000/posts]
  • Image credit: http://www.visionmasterdesigns.com/blog
  • Example from — http://ruby-lang.org/en/about
  • http://news.ycombinator.com/item?id=678501
  • Slides - WordPress.com — Get a Free Blog Here

    1. 1. RUBY ON RAILS Introduction to Ruby
    2. 2. What is Ruby?
    3. 3. Ruby is: from Japan from Japan Yukihiro “Matz” Matsumoto
    4. 4. Ruby is: a scripting language a scripting language “Ruby is simple in appearance, but is very complex inside, just like our human body.” – Matz
    5. 5. Ruby is: Object Oriented Object Oriented “I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python.” – Matz 5.times { print "We *love* Ruby -- it's outrageous!" }
    6. 6. Ruby is: Flexible Flexible class Numeric def plus(x) self.+(x) end end y = 5.plus 6 # y is now equal to 11
    7. 7. Ruby has: Blocks Blockssearch_engines = %w[Google Yahoo MSN].map do |engine| "http://www." + engine.downcase + ".com" end # search_engines = [‘http://www.google.com’, http://www .yahoo.com’, ‘http://www.msn.com’]
    8. 8. Ruby is: Single Inheritance Single Inheritance class MyArray include Enumerable end
    9. 9. Ruby is: Pretty Easy to Read Pretty Easy to Read var could be a local variable. @var is an instance variable. $var is a global variable.
    10. 10. What is Rails?
    11. 11. Rails is: A Web Application Framework written in Ruby
    12. 12. What’s the advantage? Functionality common to many web applications abstracted into a stable, tested code base. Rails leverages the RubyGem code packaging system to make installing and versioning libraries of code exceedingly easy.
    13. 13. So why is Rails unique? Convention Over Configuration approach to get you started quickly. DRY principles and built-in testing to help ensure your code is lasting.
    14. 14. How easy is it, really? Let’s do an example.
    15. 15. How is it Structured? Model View Controller Model=State, View=Response to User, Controller=Logic
    16. 16. How does that show up in Rails? Model — ActiveRecord Controller—ActionController View—ActionView
    17. 17. MVC in Webapps
    18. 18. Model OO abstraction for RDB Classes—Tables Objects—Rows Queries & Operations—Class Methods class Client < ActiveRecord::Base has_one :address has_one :mailing_address has_many :orders end
    19. 19. View Templates for HTML documents ERB—Embedded Ruby
    20. 20. Controller Interface between user, model and view. This is where you line everything up.
    21. 21. Let’s go back to the example
    22. 22. Assignment “Seems really pricey for a relatively simple software like this. Someone write an opensource alternative? it looks like something that can be thrown together in a weekend.” — ktharavaad writing about Stack Overflow @ news.ycombinator.com
    23. 23. Rewrite Stack Overflow Requirements: Questions, Responses, Users, Voting Go further if you feel ambitious.
    24. 24. Tools Required Text editor, Terminal, script/server, http://api.rubyonrails.org/, http://www.ruby-doc.org/core/, http://guides.rubyonrails.org/, script/console

    ×