are you using ruby on rails - patched software · 2007-04-22 · migrations 1. gregg creates...

75
Are you using Ruby on Rails? Should you? Come have a seat, and we’ll figure it out Talk begins at 5 PM Learn how to create happy programmers, and 10 real world benefits to using Rails

Upload: others

Post on 09-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Are you using Ruby on Rails?

Should you?

Come have a seat, and we’ll figure it out

Talk begins at 5 PM

Learn how to create happy programmers,and 10 real world benefits to using Rails

Page 2: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Warning

Page 3: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Warning

I am not an expert

Page 4: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Warning

I am not an expert

I am a bad programmer

Page 5: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Where are we going?

Page 6: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Meet Tim

Page 7: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

“What makes you enjoy being a painter Tim?”

“I enjoy being creative, and finding new things to paint”

“I enjoy creating beautiful pieces of art”

“I get satisfaction when people purchase my Art”

Page 8: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Happiness comes from:

The Inspiration

The Challenge

The Reward of Success

Page 9: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Meet Bob

Page 10: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

“What makes you enjoy being a programmer Bob?”

“I enjoy thinking of creative ways to solve problems”

“I enjoy creating somethingwith my own two hands, and watching it succeed”

“I enjoy getting positivefeedback from my clients”

Page 11: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Happiness comes from:

The Inspiration

The Challenge

The Reward of Completion

Page 12: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Programmers don’t like programming

Page 13: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

How do we increaseprogrammer happiness?

Page 14: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

How do we increaseprogrammer happiness?

Tools that are easier to learn

Page 15: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

How do we increaseprogrammer happiness?

Tools that are easier to learn

Tools that make problems easier to solve

Page 16: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

How do we increaseprogrammer happiness?

Tools that are easier to learn

Tools that make problems easier to solve

Tools that increase the chance of success

Page 17: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers
Page 18: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Ruby A Programming Language 1993 by Yukihiro “Matz” Matsumoto

Page 19: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Ruby A Programming Language 1993 by Yukihiro “Matz” Matsumoto

Ruby on Rails Web Application Framework 2004 by David Heinemeier Hansson

Page 20: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

Page 21: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

Understandable

Page 22: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

UnderstandablePrinciple of Least Surprise

(POLS)

Page 23: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

UnderstandablePrinciple of Least Surprise

(POLS)

Transparent

Page 24: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

Easy to learn how it works

Principle of Least Surprise (POLS)

Transparent

Page 25: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

Easy to learn how it works

Easy to guess how it works

Transparent

Page 26: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Ruby solve for me?

Easy to learn how it works

Easy to guess how it works

Easy to read how it works

Page 27: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Coderspeak3.times { print “Ho!” }

exit unless shopping_cart.size > 0

[‘toast’, ‘cheese’].each { |food| print food.capitalize }

Page 28: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

What problems does Rails solve for me?

Page 29: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

There are too many ways to create web applications

Problem #1

Page 30: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

There are too many ways to create web applications

Problem #1

Solution

The Golden Path

Page 31: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

There are too many ways to create web applications

Problem #1

Solution

The Golden Path

Model View ControllerMVC Framework

Page 32: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

There are too many ways to create web applications

Problem #1

Solution

The Golden Path

MVC Framework

Convention Over Configuration

Page 33: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThe glue between the database and the code

Page 34: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThe glue between the database and the code

posts table

Page 35: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThe glue between the database and the code

posts table

1. Create the the model file

Page 36: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThe glue between the database and the code

posts table

1. Create the the model filepost.rb

Page 37: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThe glue between the database and the code

posts table

1. Create the the model filepost.rb

There is no step 2

Page 38: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThis means anywhere in my app, I can run

Post.find(:all)

Post.count(:all)

Post.find_by_id(3)

Post.find(:all, :order => “created_on”)

Post.find(:all, :conditions => { :id => 2..9 })

Page 39: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThis means anywhere in my app, I can run

for post in Post.find(:all) print “post title = “ + post.title print “post body = “ + post.bodyend

Page 40: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

ActiveRecordThis means anywhere in my app, I can run

for post in Post.find(:all) print “post title = ” + post.title print “post body = ” + post.bodyend

Post.find_by_title_and_body(“this”, “that”)

Page 41: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Our website was coded for one type of database, and now we need to change

Problem #2

Page 42: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Our website was coded for one type of database, and now we need to change

Problem #2

Solution

ActiveRecordNot dependent on your database

Page 43: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Our website isn’t maintainableor extendable

Problem #3

Page 44: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Our website isn’t maintainableor extendable

Problem #3

Solution

Keep things modular MVC

Page 45: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Our website isn’t maintainableor extendable

Problem #3

Solution

Keep things modular MVC

Don’t Repeat Yourself DRY

Page 46: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Our website isn’t maintainableor extendable

Problem #3

Solution

Keep things modular MVC

Don’t Repeat Yourself DRY

Full Suite of Testing Tools

Page 47: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Page 48: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Coder Gregg Coder Jason

The Database

Page 49: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Coder Gregg Coder Jason

The Database

Needs to add a table to the database

Page 50: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Coder Gregg Coder Jason

The Database

Needs to add a table to the database

1. Write up the table SQL and send it to everyone

Page 51: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Coder Gregg Coder Jason

The Database

Needs to add a table to the database

1. Write up the table SQL and send it to everyone

2. Take a database snapshot and send it to everyoneor

Page 52: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Solution

Migrations

Page 53: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Versioning the Database

Problem #4

Solution

Migrations

1. Gregg creates 001_add_table.rb2. Gregg checks this file into the source repository3. His coworkers check out the code, and run:

“rake db:migrate”

Page 54: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

A Sample Migrationclass AddTable < ActiveRecord::Migration def self.up create_table :cars do |t| t.column :model, :string t.column :year, :int t.column :make, :string t.column :comments, :text end end def self.down drop_table :cars endend

001_add_table.rb

Page 55: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Every time I change the database I have to add 20 lines of code

Problem #5

Page 56: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Every time I change the database I have to add 20 lines of code

Problem #5

Solution

With Rails, I don’t have to add any lines of code

Page 57: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

We want to integrate AJAX, butwithout a javascript expert.

Problem #6

Page 58: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

We want to integrate AJAX, butwithout a javascript expert.

Problem #6

Solution

Javascript Helpers & RJSYour pathway to Prototype and Scriptaculous

Page 59: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

If our lead developer quits, we’re totally screwed

Problem #7

Page 60: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Problem #7

Solution

There is only one way to create a Ruby on Rails application

If our lead developer quits, we’re totally screwed

Page 61: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Creating web services require twice as much work

Problem #8

Page 62: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Creating web services require twice as much work

Problem #8

Solution

Only code once @post = Post.find(1) respond_to { |format| format.html { render :action => ‘view_post’ } format.xml { render :xml => @post.to_xml } format.js { render :action => ‘appear_post’ }}

Page 63: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

We’ve run up into limitations of the framework itself

Problem #9

Page 64: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

We’ve run up into limitations of the framework itself

Problem #9

Solution

Flexible (Reprogrammable)Tools

Page 65: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

The biggest concernProblem #10

Page 66: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers
Page 67: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Will it scale?

Page 68: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Will it scale?

Page 69: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

100% Hardware & Server Config

Scaling is

Page 70: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

100% Hardware & Server Config

Scaling is

FALSE

Page 71: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

50% Hardware & Server Config50% Good Coding & Cached Data

Scaling is

Page 72: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

50% Hardware & Server Config50% Good Coding & Cached Data

Scaling is

Rails comes with 3 caching mechanisms

Page 73: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

To Sum Up

Page 74: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

Even if you’renot an expert

and might be abad programmer

you can still create advancedweb applications

Page 75: Are you using Ruby on Rails - Patched Software · 2007-04-22 · Migrations 1. Gregg creates 001_add_table.rb 2. Gregg checks this file into the source repository 3. His coworkers

To Learn:Agile Web Development with Rails

by Dave Thomas & David Heinemeier Hansson Ruby For Rails by David Black

My Blog: www.RailsEnvy.com

My Email: [email protected]