Rubyon Rails

Post on 15-May-2015

447 views 0 download

Tags:

Transcript of Rubyon Rails

Ruby on RailsThe most awesome thing to hit

the internet since Rick Astley

UW – Eau Claire Web-Centric Programming

May 30, 2009

Presenter: Kevin Gisi

kevin.gisi@gmail.com

Twitter: gisikw

About the Presenter

• Computer Engineering

• LTS – Web Development

• Independent Contractor

• Co-founder of the Eau Claire Ruby User Group

• Winner of the RailsRumble “Most Innovative” award

• Pragmatic Programmers Author

What is Ruby?

• Developed in the 1990’s in Japan

• C-based interpreted language

• Dynamically (“duck”) typed

• Based on Perl and Smalltalk

• Many different implementations (YARV, JRuby, Rubinius, IronRuby, MacRuby)

• Completely open-source

What is Rails?

• Web application framework

• Extracted from 37Signals in 2004

• Model – View – Controller

• Convention over Configuration

• Don’t Repeat Yourself (DRY)

• Representational State Transfer (REST)

• Completely open-source

Convention: REST

• Everything is a resource

• You Create (POST), Read (GET), Update (PUT), and Destroy (DELETE) resources

• Also need New, and Edit pages

Convention: URLs

• URLs should be pretty!

• Index /listings

• New /listings/new

• Show /listings/5

• Edit /listings/5/edit

• Create /listings

• Update /listings/5

• Destroy /listings/5

Ruby on Rails Tools

• RubyGems – Package Manager

• Plugins – Adds functionality

• Generators – Writes code for you

• Console – Access runtime environment

Server Structure

Front-endApache/Nginx

Server – 5000Mongrel

Server – 5001Mongrel

Server – 5002Mongrel

Database

What Runs On Rails?

• Hulu

• Twitter

• 37 Signals

• Blinksale

• Many UWEC Applications

2-Minute Ruby• Everything is an object

• Anything other than false or nil is “true”

• Functions always return something

• Classes can be modified at runtime

• @instance_variables

• @@class_variables

• CONSTANTS

2-Minute RubyArrays [ ]

• Ordered, dynamically sized

• my_array << value

• my_array[4]

• my_array.pop

2-Minute RubyHashes { }

• Not ordered

• Key, value pairs

• Keys are traditionally :symbols

• Awesome for methods

2-Minute RubyMethods

def foo(params = {})

“You said” + params[:message]

end

2-Minute RubyMethods (continued)

• mutate!, boolean?, assignment=

def method_missing

“We don’t do that!”

end

2-Minute RubyClasses

class Awesome

attr_accessor :pie

end

a = Awesome.new

a.pie

2-Minute RubyBlocks

my_array.each do |value|

puts “It was #{value}”

end

2-Minute RubyPretend I Didn’t Show You This

eval(“foo = 5”)

3-Minute RailsModels

• Validations

• Business logic

• Other object methods

• Anything that doesn’t go somewhere else

3-Minute RailsControllers

• Before filters

• Public actions

• Keep them small!

3-Minute RailsViews

• Display

• Mix of HTML and ERb (Embedded Ruby)

• Avoid logic here!

3-Minute RailsHelpers

• Custom embedded Ruby:

def paypal

“<form>Paypal donate code</form>”

end

Boo Slides!Let’s be awesome code

monkeys instead!