Slides - WordPress.com Get a Free Blog Here

24
RUBY ON RAILS Introduction to Ruby

Transcript of Slides - WordPress.com Get a Free Blog Here

Page 1: Slides - WordPress.com  Get a Free Blog Here

RUBY ON RAILSIntroduction to Ruby

Page 2: Slides - WordPress.com  Get a Free Blog Here

What is Ruby?

Page 3: Slides - WordPress.com  Get a Free Blog Here

Ruby is: from Japan

Yukihiro “Matz” Matsumoto

Page 4: Slides - WordPress.com  Get a Free Blog Here

Ruby is: a scripting language

“Ruby is simple in appearance, but is very complex inside, just like our human body.” – Matz

Page 5: Slides - WordPress.com  Get a Free Blog Here

Ruby is: 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!" }

Page 6: Slides - WordPress.com  Get a Free Blog Here

Ruby is: Flexible

class Numeric  def plus(x)    self.+(x)  endendy = 5.plus 6# y is now equal to 11

Page 7: Slides - WordPress.com  Get a Free Blog Here

Ruby has:Blocks

search_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’]

Page 8: Slides - WordPress.com  Get a Free Blog Here

Ruby is:Single Inheritance

class MyArray  include Enumerableend

Page 9: Slides - WordPress.com  Get a Free Blog Here

Ruby is:Pretty Easy to

Read

var could be a local variable.@var is an instance variable.

$var is a global variable.

Page 10: Slides - WordPress.com  Get a Free Blog Here

What is Rails?

Page 11: Slides - WordPress.com  Get a Free Blog Here

Rails is:A Web Application Framework

written in Ruby

Page 12: Slides - WordPress.com  Get a Free Blog Here

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.

Page 13: Slides - WordPress.com  Get a Free Blog Here

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.

Page 14: Slides - WordPress.com  Get a Free Blog Here

How easy is it, really?

Let’s do an example.

Page 15: Slides - WordPress.com  Get a Free Blog Here

How is it Structured?

Model View ControllerModel=State, View=Response to User, Controller=Logic

Page 16: Slides - WordPress.com  Get a Free Blog Here

How does that show up in Rails?

Model — ActiveRecordController—ActionController

View—ActionView

Page 17: Slides - WordPress.com  Get a Free Blog Here

MVC in Webapps

Page 18: Slides - WordPress.com  Get a Free Blog Here

ModelOO abstraction for RDB

Classes—TablesObjects—Rows

Queries & Operations—Class Methodsclass Client < ActiveRecord::Base has_one :address has_one :mailing_address has_many :ordersend

Page 19: Slides - WordPress.com  Get a Free Blog Here

ViewTemplates for HTML documents

ERB—Embedded Ruby

Page 20: Slides - WordPress.com  Get a Free Blog Here

ControllerInterface between user, model and view.

This is where you line everything up.

Page 21: Slides - WordPress.com  Get a Free Blog Here

Let’s go back to the example

Page 22: Slides - WordPress.com  Get a Free Blog Here

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

Page 23: Slides - WordPress.com  Get a Free Blog Here

Rewrite Stack Overflow

Requirements: Questions, Responses, Users, VotingGo further if you feel ambitious.

Page 24: Slides - WordPress.com  Get a Free Blog Here

Tools RequiredText editor,Terminal,

script/server,http://api.rubyonrails.org/,

http://www.ruby-doc.org/core/,http://guides.rubyonrails.org/,

script/console