81
Dr Nic drnicwilliams.com drnicacademy .com What’s cool about Rails? Remember: * setup for demo of magic_model_generator (pp 36) * set font size of database.yml to large

RubyEnRails2007 - Dr Nic Williams - Keynote

Tags:

Embed Size (px)

DESCRIPTION

Dr Nic gives his report on what's cool with Rails right now

Citation preview

Page 1: RubyEnRails2007 - Dr Nic Williams - Keynote

Dr Nicdrnicwilliams.comdrnicacademy.com

What’s cool about Rails?

Remember:* setup for demo of magic_model_generator (pp 36)* set font size of database.yml to large

Page 2: RubyEnRails2007 - Dr Nic Williams - Keynote

Dr Nic

Page 3: RubyEnRails2007 - Dr Nic Williams - Keynote

Dr Nic’sMagic Models

Page 4: RubyEnRails2007 - Dr Nic Williams - Keynote

MyConfPlan

Page 5: RubyEnRails2007 - Dr Nic Williams - Keynote

CompositePrimary Keys

Page 6: RubyEnRails2007 - Dr Nic Williams - Keynote

MagicMulti-Connections

Page 7: RubyEnRails2007 - Dr Nic Williams - Keynote

MagicMulti-Connections

As seen on

DHH’sblog

Page 8: RubyEnRails2007 - Dr Nic Williams - Keynote

NewGemGenerator

$ newgem <gem>

Page 9: RubyEnRails2007 - Dr Nic Williams - Keynote

NewGemGenerator

$ newgem <gem>

As seen in

Page 10: RubyEnRails2007 - Dr Nic Williams - Keynote

Magic ModelGenerator

Page 11: RubyEnRails2007 - Dr Nic Williams - Keynote

Magic ModelGenerator

As seen in

??

Page 12: RubyEnRails2007 - Dr Nic Williams - Keynote

why?

Page 13: RubyEnRails2007 - Dr Nic Williams - Keynote

Dr Nic’s

Page 14: RubyEnRails2007 - Dr Nic Williams - Keynote

Dr Nic’sAcademy

Page 15: RubyEnRails2007 - Dr Nic Williams - Keynote

Dr Nic’sAcademy

“Beginning Ruby on Rails”July 7/8 - Netherlands

Page 16: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConf

Page 17: RubyEnRails2007 - Dr Nic Williams - Keynote

So why is important?

Page 18: RubyEnRails2007 - Dr Nic Williams - Keynote

Why is important?

Page 19: RubyEnRails2007 - Dr Nic Williams - Keynote

Why is important?

When do I use ?

Page 20: RubyEnRails2007 - Dr Nic Williams - Keynote

Why is important?

Merb Camping CGI Mongrel Handlers

When do I use ?

Page 21: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConfBetween last year and this year, I’ve realised they aren’t “Railsconfs”, but...

Page 22: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConfBetween last year and this year, I’ve realised they aren’t “Railsconfs”, but...

Page 23: RubyEnRails2007 - Dr Nic Williams - Keynote

RubyConfAbout web development and other things

Page 24: RubyEnRails2007 - Dr Nic Williams - Keynote

Websites are textAnd it doesn’t matter how the text gets to the browser

Page 25: RubyEnRails2007 - Dr Nic Williams - Keynote

<html> <head> <title>Hello world</title> </head> <body> <p>Hello World</p> </body></html>

Here’s some text that you might send

Page 26: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsWhen you come to Rails you quickly learn there are many things you need to get good at quickly...

I just want to talk about these 3...

Page 27: RubyEnRails2007 - Dr Nic Williams - Keynote

Javascript HTML CSS

RubyRailsGems

UnixDatabasesRake

When you come to Rails you quickly learn there are many things you need to get good at quickly...

I just want to talk about these 3...

Page 28: RubyEnRails2007 - Dr Nic Williams - Keynote

Javascript HTML CSS

RubyRailsGems

UnixDatabasesRake

When you come to Rails you quickly learn there are many things you need to get good at quickly...

I just want to talk about these 3...

Page 29: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConf 2006To understand Rails and where its going, let’s look at rails 1.0

Page 30: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConf 2006

“Can we make $$$ from Rails?”

To understand Rails and where its going, let’s look at rails 1.0

Page 31: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConf 2007

Page 32: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConf 2007

“Yes.”

Page 33: RubyEnRails2007 - Dr Nic Williams - Keynote

RailsConf 2007

Ok, now let’s look at the latest ways to generate text on the web...

“Because its just text generation”

Page 34: RubyEnRails2007 - Dr Nic Williams - Keynote

“Does it scale?”

Everyone worries about requests per second; but I think its more important to worry about the cost per new feature. Rails is structured to make it easy to design and implement new stuff.

Page 35: RubyEnRails2007 - Dr Nic Williams - Keynote

“Does it scale?”

“Yes. Just add more controllers.”Everyone worries about requests per second; but I think its more important to worry about the cost per new feature. Rails is structured to make it easy to design and implement new stuff.

Page 36: RubyEnRails2007 - Dr Nic Williams - Keynote

RESTful controllersclass PeopleController < ApplicationController # GET all or search def index... def show... def new... def edit... def create... def update... def destroy...end

Page 37: RubyEnRails2007 - Dr Nic Williams - Keynote

RESTful controllersclass PeopleController < ApplicationController # GET all or search def index... def show... def new... def edit... def create... def update... def destroy...end

class PeopleController < ApplicationController # GET all or search def index... def show... def new... def edit... def create... def update... def destroy...end

CRUD operations

Page 38: RubyEnRails2007 - Dr Nic Williams - Keynote

RESTful routes

/people/show/1 => /people/1

/people/some_action/45 => /people/45/some_action

Its now cool to use restful routing. The benefit is you can remove the tail of a url, and the url is still meaningful.

Page 39: RubyEnRails2007 - Dr Nic Williams - Keynote

class PeopleController < ApplicationController

def create @person = Person.create(params[:person]) respond_to do |format| format.html { redirect_to person_url(@person) } format.xml { render :status => :created, :location => person_url(@person), ... } end endend

RESTful result typesOne of the main agreements about convention in Rails is RESTfulness.Same actions, but new paradigm.

From developer side, you can return more data formats with the same actions.

Page 40: RubyEnRails2007 - Dr Nic Williams - Keynote

class PeopleController < ApplicationController

def create @person = Person.create(params[:person]) respond_to do |format| format.html { redirect_to person_url(@person) } format.xml { render :status => :created, :location => person_url(@person), ... } end endend

RESTful result typesOne of the main agreements about convention in Rails is RESTfulness.Same actions, but new paradigm.

From developer side, you can return more data formats with the same actions.

Page 41: RubyEnRails2007 - Dr Nic Williams - Keynote

Any format you want

respond_to do |format| format.html { render ... } format.xml { render ... } format.csv { render ... } format.js { render ... } formal.foobar { render ... }end

Page 42: RubyEnRails2007 - Dr Nic Williams - Keynote

ActiveResource

Applications “talking” with REST

Page 43: RubyEnRails2007 - Dr Nic Williams - Keynote

ActiveResource

Applications “talking” with REST

Page 44: RubyEnRails2007 - Dr Nic Williams - Keynote

This is cool because...

class Person < ActiveResource::Base self.site = "http://contacts.drnicwilliams.com:3000/"end

Person.find_by_name "Dr Nic Williams" Who cares what REST is? This syntax is awesome.

Page 45: RubyEnRails2007 - Dr Nic Williams - Keynote

Learn more?

Read the README and CHANGELOG for ActiveResource

http://dev.rubyonrails.org/browser/trunk/activeresource/README

Page 46: RubyEnRails2007 - Dr Nic Williams - Keynote

Jester: REST for Javascript

Base.model("Person", { plural: "people", prefix: "http://drnicwilliams.com:3000"})

Person.find("all", { premium: true }, { onSuccess: callback })

This #find call is asynchronous and invokes callback on complete.

by Eric Mill

Page 47: RubyEnRails2007 - Dr Nic Williams - Keynote

“Logical” servers for the connector1) Jumpstart/PXE Boot

2) Monitoring

3) Auditing

4) Logging

5) Provisioning and configuration management

6) DHCP/LDAP for server identification/authentication and control (at dual for failover)

7) DNS: DNS cache and resolver, and a (private) DNS system (4x + 2; 2+ sites)

8) DNS MySQL (4x + 2, dual masters with slaves per DNS node, innodb tables)

9) SPAM filtering servers (files to NFS store and tracking to postgresql)

10) SPAM database setup (postgresql)

11) SPAM NFS store

12) SMTP proxies and gateways out

13) SMTP proxies and gateways in (delivery to clusters to Maildir over NFS)

14) Mail stores

15) IMAP proxy servers

16) IMAP servers

17) User LDAP servers

18) User long running processes

19) User postgresql DB servers

20) User web servers

21) User application servers

22) User File Storage (NFS)

23) Joyent Organization Provisioning/Customer panel servers (web, app, database)

24) iSCSI storage systems

25) Chat servers

26) Load balancer/proxies/static caches

...Jason Hoffman, Railsconf 2007

Page 48: RubyEnRails2007 - Dr Nic Williams - Keynote

Guess which is “Rails”?

Jason Hoffman, Railsconf 2007

Page 49: RubyEnRails2007 - Dr Nic Williams - Keynote

Jason Hoffman, Railsconf 2007

Page 50: RubyEnRails2007 - Dr Nic Williams - Keynote

A process of ongoing improvement

Page 51: RubyEnRails2007 - Dr Nic Williams - Keynote

Hosting

Don’t deploy Rails to Amazon’s EC2

EC2 have virtual storage - if you lose your instance, you lose data. Backup hourly.

Use EC2 for other processes on demand.

Run Ruby scripts on Amazon’s EC2

Page 52: RubyEnRails2007 - Dr Nic Williams - Keynote

Deployment

Capistrano - by Jamis Buck

+Deprec - by Mike Bailey deprec =

deployment recipies

Page 53: RubyEnRails2007 - Dr Nic Williams - Keynote

deprec - easy peasy

cap install_rails_stackcap setupcap deploy_with_migrationscap restart_apache

Slap ubuntu on a machine and go.

Page 54: RubyEnRails2007 - Dr Nic Williams - Keynote

install_rails_stack

task :install_rails_stack do setup_user_perms enable_universe disable_cdrom_install install_packages_for_rails install_rubygems install_gems install_apacheend

The process of deploying rails generically is being solved

Page 55: RubyEnRails2007 - Dr Nic Williams - Keynote

Story of 200 database tables

Page 56: RubyEnRails2007 - Dr Nic Williams - Keynote

magic_model_generator

magicmodels.rubyforge.org

Page 57: RubyEnRails2007 - Dr Nic Williams - Keynote

magic_model_generator

$ sudo gem install magic_model_generator$ rails magic_show$ cd magic_show # point database.yml to legacy database$ rake db:migrate # check /db/schema.rb contains all tables$ ruby script/generate magic_model # check /app/models contains model files

For demo:$ pgstart$ rails magic_show -d postgresql$ database.yml: database: activerecord_unittest$ Kill textmate and reload it fresh from magic_show folder$ Have /db and /app/models folders open and empty$ Pump up font size$ iTerm open to magic_show folder

Now, demo is ready

# Show post.rb as example

Page 58: RubyEnRails2007 - Dr Nic Williams - Keynote

RubyGems are goodRubyGems

Page 59: RubyEnRails2007 - Dr Nic Williams - Keynote

Instead of plugins, use gems

Page 60: RubyEnRails2007 - Dr Nic Williams - Keynote

Dependencies

Page 61: RubyEnRails2007 - Dr Nic Williams - Keynote

Version numbers

Page 62: RubyEnRails2007 - Dr Nic Williams - Keynote

Use outside of Rails

Page 63: RubyEnRails2007 - Dr Nic Williams - Keynote

Non-ruby code

Page 64: RubyEnRails2007 - Dr Nic Williams - Keynote

“But I don’t know how?”

Page 65: RubyEnRails2007 - Dr Nic Williams - Keynote

hoe - Ryan Davis

Page 66: RubyEnRails2007 - Dr Nic Williams - Keynote

hoe - Ryan Davisseattle.rb - ZenTest/autotest

Page 67: RubyEnRails2007 - Dr Nic Williams - Keynote

hoe - Ryan Davisseattle.rb - ZenTest/autotest

# Rakefilehoe = Hoe.new(GEM_NAME, VERS) do |p| p.author = AUTHOR p.description = DESCRIPTION p.email = EMAIL p.summary = SUMMARY p.url = HOMEPATHend

Its easier to write a Gem than not to!

Page 68: RubyEnRails2007 - Dr Nic Williams - Keynote

rake

Page 69: RubyEnRails2007 - Dr Nic Williams - Keynote

rake

Page 70: RubyEnRails2007 - Dr Nic Williams - Keynote

History.txt== 0.2.0 2007-06-03

* Added more foo into foo.rb == 0.1.0 2007-06-02

* Foo and Bar now in own files* Using Hoe

Page 71: RubyEnRails2007 - Dr Nic Williams - Keynote

History.txtManifest.txtREADME.txtRakefilebin/gemsonrailslib/gemsonrails.rblib/gemsonrails/version.rbscripts/txt2htmlsetup.rbtemplates/init.rbtemplates/tasks_gems_freeze.raketemplates/tasks_gems_link.raketemplates/tasks_gems_unfreeze.raketemplates/tasks_load_tasks_in_gems.raketest/test_gemsonrails.rbtest/test_helper.rbwebsite/index.htmlwebsite/index.txtwebsite/javascripts/rounded_corners_lite.inc.jswebsite/stylesheets/screen.csswebsite/template.rhtml

Manifest.txt

ordered list of published files

Page 72: RubyEnRails2007 - Dr Nic Williams - Keynote

History.txtManifest.txtREADME.txtRakefilebin/gemsonrailslib/gemsonrails.rblib/gemsonrails/version.rbscripts/txt2htmlsetup.rbtemplates/init.rbtemplates/tasks_gems_freeze.raketemplates/tasks_gems_link.raketemplates/tasks_gems_unfreeze.raketemplates/tasks_load_tasks_in_gems.raketest/test_gemsonrails.rbtest/test_helper.rbwebsite/index.htmlwebsite/index.txtwebsite/javascripts/rounded_corners_lite.inc.jswebsite/stylesheets/screen.csswebsite/template.rhtml

Manifest.txt

ordered list of published files

rake check_manifest

Page 73: RubyEnRails2007 - Dr Nic Williams - Keynote

NewGemGenerator

$ newgem <gemname>

newgem.rubyforge.org

Page 75: RubyEnRails2007 - Dr Nic Williams - Keynote

Test::Unit

RSpec

or

newgem.rubyforge.org

Page 76: RubyEnRails2007 - Dr Nic Williams - Keynote

Finally...

Page 77: RubyEnRails2007 - Dr Nic Williams - Keynote

JRuby is cool

Page 78: RubyEnRails2007 - Dr Nic Williams - Keynote

drnicacademy.com

Dr Nic Academy

Learn on !

Page 79: RubyEnRails2007 - Dr Nic Williams - Keynote

What: Beginning RailsWhen: July 7 and 8thWhere: Amsterdam +/-BYO: LaptopCost: 975€

drnicacademy.com

Page 80: RubyEnRails2007 - Dr Nic Williams - Keynote

What: Beginning RailsWhen: July 7 and 8thWhere: Amsterdam +/-BYO: LaptopCost: 975€

600€ - “rubyenrails”drnicacademy.com

Page 81: RubyEnRails2007 - Dr Nic Williams - Keynote

drnicwilliams.com

by Dr Nic

Enjoy En !

drnicacademy.com