rails 2.0 presentation

99
Rails 2.0 “evolution, not revolution”

Upload: scott-chacon

Post on 10-May-2015

9.261 views

Category:

Business


0 download

DESCRIPTION

These are the slides from my presentation on Rails 2.0 at the Silicon Valley Ruby on Rails Meetup on Dec 13.

TRANSCRIPT

Page 1: Rails 2.0 Presentation

Rails 2.0“evolution, not revolution”

Page 2: Rails 2.0 Presentation

Rails 2.0 OverviewRESTful web architectures

some small feature maturations

removal of features determined to be not essential

Page 3: Rails 2.0 Presentation

Action Pack

ActionController + ActionView

Page 4: Rails 2.0 Presentation

Multiview

show.html.erbindex.atom.builderedit.iphone.haml

“Machine-Gunning .rhtml and .rxml”

(action.mimetype.renderer)

Page 5: Rails 2.0 Presentation

Partial Layouts

Page 6: Rails 2.0 Presentation

Partial Layouts

Page 7: Rails 2.0 Presentation

Routing Resources

Page 8: Rails 2.0 Presentation

link_to ‘variants’, admin_product_variants_url(@product)

/admin/products/:product_id/variants

Routing Namespaces

Page 9: Rails 2.0 Presentation

Record Identification

redirect_to(person)link_to(person.name, person)

form_for(person)

Page 10: Rails 2.0 Presentation

HTTP Authentication

Page 11: Rails 2.0 Presentation

authenticate_or_request_with_http_basic

Page 12: Rails 2.0 Presentation

Exception Handling

Page 13: Rails 2.0 Presentation

rescue_from

controllers/application.rb

Page 14: Rails 2.0 Presentation

Atom Feed Helper

Page 15: Rails 2.0 Presentation

Stolen from the DHH announcement

Page 16: Rails 2.0 Presentation

Mime::Type Predicates

controller.request.format.html?controller.request.format.xml?

Page 17: Rails 2.0 Presentation

PerformanceAsset ServersAsset Caching

Cookie Based Sessions

Page 18: Rails 2.0 Presentation

Asset Servers

most browsers will only make up to two simultaneous connections

to any one domain

Page 19: Rails 2.0 Presentation

Asset Servers

config/environment.rb

Page 20: Rails 2.0 Presentation

Asset Servers

config/environment.rb

will always use the same server for a single file

Page 21: Rails 2.0 Presentation

Asset Caching

Page 22: Rails 2.0 Presentation

Cookie Based Sessions

Page 23: Rails 2.0 Presentation

Cookie Sessions Security

example stolen from ryan daigle

Page 24: Rails 2.0 Presentation

Security

CSRF Protection

TextHelper#sanitize

HTTP only cookies

Page 25: Rails 2.0 Presentation

CSRF Protection

Page 26: Rails 2.0 Presentation

Active Resource

Short Overview of Resources

Page 27: Rails 2.0 Presentation

Active Resource

A consumer of RESTful resources

Page 28: Rails 2.0 Presentation

Active Resource

A consumer of RESTful resourcesAs ActiveRecord is a consumer of

relational database resources

Page 29: Rails 2.0 Presentation

ActiveResource Models

Page 30: Rails 2.0 Presentation

Active Resource ActionsModel request Http REST

operation request

body Request URI Response

find(id) GET n/a /people/id.xml <XML>

save (update) PUT <XML> /people/id.xmlStatus:

200 OK

save (create) POST <XML> /people Location:http://x/people/id.xml

destroy DELETE n/a /people/id.xmlStatus:

200 OK

list GET n/a /people <XML>

credit: ryan diagle

Page 31: Rails 2.0 Presentation

demo

Page 32: Rails 2.0 Presentation

Active Record

Page 33: Rails 2.0 Presentation

Validations

Page 34: Rails 2.0 Presentation

:allow_blankvalidates_numericality

Page 35: Rails 2.0 Presentation

:allow_blankvalidates_numericality

Page 36: Rails 2.0 Presentation

Sexy Migrations

Page 37: Rails 2.0 Presentation

“Cold Shower” Migrations

Page 38: Rails 2.0 Presentation

Err Sexy Migrations

Page 39: Rails 2.0 Presentation

Rails 2.0 Sexy4 fewer lines + rails programmers == sexy

Page 40: Rails 2.0 Presentation

References

Page 41: Rails 2.0 Presentation

Query Cache

Page 42: Rails 2.0 Presentation

Query Cache Logging

Page 43: Rails 2.0 Presentation

Disabling the Query Cache

Page 44: Rails 2.0 Presentation

FixturesFoxy Fixtures

Collection FixturesFixture Performance

Page 45: Rails 2.0 Presentation

Foxy Fixtures

conferences.yml

places.yml

Page 46: Rails 2.0 Presentation

Foxy Fixtures

conferences.yml

places.yml

Page 47: Rails 2.0 Presentation

Collection Fixtures

Now

Was

Page 48: Rails 2.0 Presentation

Data Exchange

to_xml, from_xmlto_json, from_json

Page 50: Rails 2.0 Presentation

to_xml

Page 51: Rails 2.0 Presentation

Other Stuff

Page 52: Rails 2.0 Presentation
Page 53: Rails 2.0 Presentation

rake

Page 54: Rails 2.0 Presentation

rake notes

Page 55: Rails 2.0 Presentation

rake notes

Page 56: Rails 2.0 Presentation

rake notes

Page 57: Rails 2.0 Presentation

rake db

rake db:createrake db:create:all

rake db:droprake db:drop:allrake db:reset

rake db:rollbackrake db:version

Page 58: Rails 2.0 Presentation

rake routes

Page 59: Rails 2.0 Presentation
Page 60: Rails 2.0 Presentation
Page 61: Rails 2.0 Presentation

rake routesroute name, HTTP method, route path, route requirements

Page 62: Rails 2.0 Presentation
Page 63: Rails 2.0 Presentation
Page 64: Rails 2.0 Presentation
Page 65: Rails 2.0 Presentation
Page 66: Rails 2.0 Presentation

helper :all

Page 67: Rails 2.0 Presentation

rails my_new_app

Page 68: Rails 2.0 Presentation

Request Profiler

./script/performance/request -n 10 login_session.rb

RubyProf Wrapper

Page 69: Rails 2.0 Presentation

/config/initializers/

Page 70: Rails 2.0 Presentation

initializers directory

Page 71: Rails 2.0 Presentation

initializers directory

Page 72: Rails 2.0 Presentation

initializers directory

Page 73: Rails 2.0 Presentation

config/preinitializer.rbloaded before the environment files

Page 74: Rails 2.0 Presentation

Scaffolding

./script/generate scaffold conference name:string description:text start_date:date end_date:date

Page 75: Rails 2.0 Presentation

Resourceful Scaffolding

Page 76: Rails 2.0 Presentation

Breakpoints

Page 77: Rails 2.0 Presentation

gem install ruby-debug

Page 78: Rails 2.0 Presentation

add ‘debugger’ to code

Page 79: Rails 2.0 Presentation

./script/server -u

Page 80: Rails 2.0 Presentation

demo

Page 82: Rails 2.0 Presentation

Upgrading to 2.0

Page 83: Rails 2.0 Presentation

Deprecations

Page 84: Rails 2.0 Presentation

with_scope

Page 85: Rails 2.0 Presentation

Components

Page 86: Rails 2.0 Presentation

Pagination

Page 87: Rails 2.0 Presentation

Object Transactions

Page 89: Rails 2.0 Presentation

ActionWebService

ActiveResource

Page 90: Rails 2.0 Presentation

syntax changes@params params[]

@session session[]

@flash flash[]

@request request[]

@env env[]

find_all find(:all)

find_first find(:first)

render_partial render :partial

:post => true :method => :post

Page 91: Rails 2.0 Presentation

start_form_tagend_form_tag

form_for doend

Page 92: Rails 2.0 Presentation

start_form_tagend_form_tag

form_tag</form>

Page 93: Rails 2.0 Presentation

Extracting to Plugins and Gems

acts_assome js helpers

commercial database adapters

Page 94: Rails 2.0 Presentation

./script/plugin install

acts_as_listacts_as_nested_setacts_as_treeauto_completein_place_editing

Page 95: Rails 2.0 Presentation

gem install activerecord-X-adapter

--source http://gems.rubyonrails.com

firebirdfrontbaseinformix

openbaseoracle

sqlserversybase

Page 96: Rails 2.0 Presentation

Upgrade Process

gem install rails -y

Page 98: Rails 2.0 Presentation

Thanks!noesbueno.org/rails2

Page 99: Rails 2.0 Presentation

Work with me @

Sr. Web Developer

Linux Systems Administrator

Sr. Game/Interaction Programmer

Computer Vision Engineer

http://www.reactrix.com/[email protected]