The Rich Get Richer: RAILS 3 PRESENTED BY OBIE FERNANDEZ Sunday, - - PowerPoint PPT Presentation

the rich get richer rails 3
SMART_READER_LITE
LIVE PREVIEW

The Rich Get Richer: RAILS 3 PRESENTED BY OBIE FERNANDEZ Sunday, - - PowerPoint PPT Presentation

HASHROCKET EXPERTLY CRAFTED WEB The Rich Get Richer: RAILS 3 PRESENTED BY OBIE FERNANDEZ Sunday, December 5, 2010 About 20k USD Sunday, December 5, 2010 About 45k USD Sunday, December 5, 2010 About 200k USD Sunday, December 5, 2010 a


slide-1
SLIDE 1

The Rich Get Richer: RAILS 3

PRESENTED BY

OBIE FERNANDEZ

HASHROCKET

EXPERTLY CRAFTED WEB Sunday, December 5, 2010
slide-2
SLIDE 2

About 20k USD

Sunday, December 5, 2010
slide-3
SLIDE 3

About 45k USD

Sunday, December 5, 2010
slide-4
SLIDE 4

About 200k USD

Sunday, December 5, 2010
slide-5
SLIDE 5

“a few million dollars”

Sunday, December 5, 2010
slide-6
SLIDE 6 Sunday, December 5, 2010
slide-7
SLIDE 7

OMG RAILS 3 ROCKS SO MUCH MORE THAN RAILS 2!!!

PRESENTED BY

OBIE FERNANDEZ

HASHROCKET

EXPERTLY CRAFTED WEB Sunday, December 5, 2010
slide-8
SLIDE 8

CAUTION: JUST A METAPHOR

How is Rails 3 Richer?

mainstream adoption maturity performance

  • pen-source mindshare
Sunday, December 5, 2010
slide-9
SLIDE 9 Sunday, December 5, 2010
slide-10
SLIDE 10 OBIE FERNANDEZ

The Rich Get Richer: RAILS 3

Presentation Overview

  • History and Context
  • What’s new
  • ActiveRecord Performance
  • Impact on Application Development
Sunday, December 5, 2010
slide-11
SLIDE 11 Sunday, December 5, 2010
slide-12
SLIDE 12

Ezra Zygmuntovich

Sunday, December 5, 2010
slide-13
SLIDE 13

merb [...] clocks in at 17,291 [loc]. Rails clocks in at 47,195. As you can see, it’s a tie.

Sunday, December 5, 2010
slide-14
SLIDE 14

Yehuda Katz

Sunday, December 5, 2010
slide-15
SLIDE 15

December 23, 2008

Sunday, December 5, 2010
slide-16
SLIDE 16

David Heinemeir Hansson

Sunday, December 5, 2010
slide-17
SLIDE 17 Photo Credit: Sebastian Delmont

Tom Mornini

Sunday, December 5, 2010
slide-18
SLIDE 18 Photo Credit: Sebastian Delmont

Tom Mornini

Sunday, December 5, 2010
slide-19
SLIDE 19 Sunday, December 5, 2010
slide-20
SLIDE 20 Sunday, December 5, 2010
slide-21
SLIDE 21

Q: How do you prevent bloating?

Ryan Sanchez's "Violet Beauregarde" ("Charlie and the Chocolate Factory")

Photo by Tera Heater/ MTV News Sunday, December 5, 2010
slide-22
SLIDE 22

A: Decoupling

http://yestheykeepmebusy.blogspot.com/2009/11/willy-wonka- halloween.html Sunday, December 5, 2010
slide-23
SLIDE 23

A: Modularity

http://superpunch.blogspot.com/2009/10/lego-violet-beauregarde-and- more.html

Sunday, December 5, 2010
slide-24
SLIDE 24

require 'active_support/concern' require 'active_support/ordered_options' require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/module/delegation' module ActiveSupport # Configurable provides a <tt>config</tt> method to store and retrieve # configuration options as an <tt>OrderedHash</tt>. module Configurable extend ActiveSupport::Concern class Configuration < ActiveSupport::InheritableOptions def compile_methods! self.class.compile_methods!(keys.reject {|key| respond_to?(key)}) end # compiles reader methods so we don't have to go through method_missing def self.compile_methods!(keys) keys.each do |key| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{key}; _get(#{key.inspect}); end RUBY end end end ...

Sunday, December 5, 2010
slide-25
SLIDE 25 Sunday, December 5, 2010
slide-26
SLIDE 26

SA

Rails 3.0

August 29, 2010

Sunday, December 5, 2010
slide-27
SLIDE 27 OBIE FERNANDEZ

The Rich Get Richer: RAILS 3

Notable Plugin Changes

  • Formtastic 1.1 (made compatible)
  • InheritedResources 1.1 (rewritten)
  • Devise (significant upgrades)
  • RSpec 2 (rewritten)
  • EmailSpec 1.0 (rewritten)
  • MetaSearch (instead of Searchlogic)
Sunday, December 5, 2010
slide-28
SLIDE 28 Sunday, December 5, 2010
slide-29
SLIDE 29 Sunday, December 5, 2010
slide-30
SLIDE 30

What’s new in Rails 3?

Sunday, December 5, 2010
slide-31
SLIDE 31 Sunday, December 5, 2010
slide-32
SLIDE 32 Sunday, December 5, 2010
slide-33
SLIDE 33

config/routes.rb

Sunday, December 5, 2010
slide-34
SLIDE 34

# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Example::Application

config.ru

Sunday, December 5, 2010
slide-35
SLIDE 35

Rack::Cache ActionDispatch::Static Rack::Lock Rack::Runtime Rails::Rack::Logger ActionDispatch::ShowExceptions ActionDispatch::RemoteIp Rack::Sendfile ActionDispatch::Callbacks ActionDispatch::Cookies ActionDispatch::Flash ActionDispatch::ParamsParser Rack::MethodOverride ActionDispatch::Head Rack::ConditionalGet Rack::ETag ActionDispatch::BestStandardsSupport

Rails 3 Middleware “Stack”

Sunday, December 5, 2010
slide-36
SLIDE 36 Sunday, December 5, 2010
slide-37
SLIDE 37 Sunday, December 5, 2010
slide-38
SLIDE 38 Sunday, December 5, 2010
slide-39
SLIDE 39

gem "rails", "3.0.1" gem 'jquery-rails' gem "mysql" gem "haml", "3.0.18" gem "decent_exposure", "1.0.0.rc1" gem "devise", "1.1.3" gem "chronic", "0.2.3" gem "seed-fu", "1.2.3", :git => "git://github.com/supaspoida/seed-fu.git" gem "block_helpers", "0.3.3" gem "will_paginate", "3.0.pre2" gem "geokit", "1.5.0" group :test do gem "capybara", "0.3.9" gem 'database_cleaner', '0.5.0' gem 'launchy', '0.3.7' gem "rspec-rails", "2.0.1" gem "mocha", "0.9.9" gem "shoulda", "2.11.3" gem "selenium-webdriver" gem "timecop", "0.3.5" gem "watchr" gem "specjour", "0.3.1" gem "email_spec", "1.0.0" end

Gemfile

Sunday, December 5, 2010
slide-40
SLIDE 40

$ bundle Fetching source index for http://rubygems.org Using rake (0.8.7) Using abstract (1.0.0) Using activesupport (3.0.1) Using builder (2.1.2) Using i18n (0.4.2) Using activemodel (3.0.1) ... Your bundle is complete! It was installed into /Users/obie/.rvm/gems/ruby-1.9.2- p0@example-application

Sunday, December 5, 2010
slide-41
SLIDE 41 Sunday, December 5, 2010
slide-42
SLIDE 42

Arel

by Nick Kallen

Sunday, December 5, 2010
slide-43
SLIDE 43 Sunday, December 5, 2010
slide-44
SLIDE 44

“closure under composition”

Sunday, December 5, 2010
slide-45
SLIDE 45

User.find :conditions => { :name => "obie" } # in Rails 3 becomes User.where(:name => "obie")

Sunday, December 5, 2010
slide-46
SLIDE 46

>> u = User.where(first_name: "Pascale"); u.to_sql => "SELECT `users`.* FROM `users` WHERE (`users`.`first_name` = 'Pascale') >> u.where(age: 21).to_sql => "SELECT `users`.* FROM `users` WHERE (`users`.`first_name` = 'Pascale') AND (`users`.`age` = 21)" >> u.order(:name).limit(20).to_sql => "SELECT `users`.* FROM `users` WHERE (`users`.`first_name` = 'Pascale') ORDER BY name LIMIT 20"

Sunday, December 5, 2010
slide-47
SLIDE 47

class Invitation < ActiveRecord::Base default_scope order("created_at DESC") scope :accepted, where("accepted_at is NOT NULL") scope :pending, where(accepted_at: nil) ... end

Scopes

Sunday, December 5, 2010
slide-48
SLIDE 48

All of my open-sourced projects share two attributes. First, the source code is extremely stylized and meant to be /read/ more than /used/. They are literary arguments in code much more than a useful piece of infrastructure. If you read the source-code to Arel you will see a highly afgected "combinator" and "interpreter" style of coding.

Nick Kallen

Sunday, December 5, 2010
slide-49
SLIDE 49

“Holy shit, Rails 3 is slow!”

Sunday, December 5, 2010
slide-50
SLIDE 50

#5098

Sunday, December 5, 2010
slide-51
SLIDE 51

joins = [{:dim_locations=>[:dim_zip, {:dim_city=> {:dim_state=>:dim_country}}]}, :dim_ages, :dim_car_makes, :dim_educations, :dim_employments, :dim_foods, :dim_genders, :dim_get_aways, :dim_home_ownerships, :dim_incomes, :dim_marital_statuses, :dim_teams] conditions = ["(dim_zips.zip_code = ? OR dim_zips.zip_code IS NULL) AND (dim_cities.city = ? OR dim_cities.city IS NULL) AND (dim_states.state_code = ? OR dim_states.state_code IS NULL) AND (dim_states.state = ? OR dim_states.state IS NULL) AND (dim_countries.country_code = ? OR dim_countries.country_code IS NULL) AND (dim_countries.country = ? OR dim_countries.country IS NULL) AND (dim_ages.age = ? OR dim_ages.age IS NULL) AND (dim_car_makes.car_make IN (?) OR dim_car_makes.car_make IS NULL) AND (dim_educations.education = ? OR dim_educations.education IS NULL) AND (dim_employments.employment = ? OR dim_employments.employment IS NULL) AND (dim_foods.food IN (?) OR dim_foods.food IS NULL) AND (dim_genders.gender = ? OR dim_genders.gender IS NULL) AND (dim_get_aways.get_away IN (?) OR dim_get_aways.get_away IS NULL) AND (dim_home_ownerships.home_ownership = ? OR dim_home_ownerships.home_ownership IS NULL) AND (dim_incomes.income = ? OR dim_incomes.income IS NULL) AND (dim_marital_statuses.marital_status = ? OR dim_marital_statuses.marital_status IS NULL) AND (dim_teams.team IN (?) OR dim_teams.team IS NULL)", "98104", "Seattle", "WA", "Washington", "US", "United States of America", "18-34", ["Ashton Martin"], "Bachelors", "Full Time", ["Brazilian"], "Male", ["France"], "Rent", "Less than 30k", "Married", ["Arizona Cardinals", "Boston Bruins"]]

Benchmark.measure do Koupon.includes(joins).where(conditions).each end => 127.930000 0.390000 128.320000 (129.897278)

Sunday, December 5, 2010
slide-52
SLIDE 52 Sunday, December 5, 2010
slide-53
SLIDE 53

O(n^2) vs O(n)

Sunday, December 5, 2010
slide-54
SLIDE 54

routing

Sunday, December 5, 2010
slide-55
SLIDE 55

ActionController::Routing::Routes.draw do |map| map.resources :schedules do |schedules| schedules.resource :timeslots end map.resources :sponsors, :member => {:enable => :post, :disable => :post} map.resources :talks map.root :controller => 'home', :action => 'index' end

BizConf::Application::Routes.draw do resources :schedules do resource :timeslots end resources :sponsors do post :enable, :disable end resources :talks root :to => 'home#index' end

config/routes.rb Rails 2.x

Sunday, December 5, 2010
slide-56
SLIDE 56

match "/api/v1/post/:id", :to => redirect("/api/article/%{id}")

Sunday, December 5, 2010
slide-57
SLIDE 57 Sunday, December 5, 2010
slide-58
SLIDE 58

ActionController

Sunday, December 5, 2010
slide-59
SLIDE 59

AbstractController::Base ActionController::Metal ActionController::Base ApplicationController

Sunday, December 5, 2010
slide-60
SLIDE 60

ActionController::Metal

Sunday, December 5, 2010
slide-61
SLIDE 61

require 'mongo' class GridfsController < ActionController::Metal def serve gridfs_path = env["PATH_INFO"].gsub("/images/", "") begin fs = Mongo::GridFileSystem.new(Mongoid.database) gridfs_file = fs.open(gridfs_path, 'r') self.response_body = gridfs_file.read self.content_type = gridfs_file.content_type rescue self.status = :file_not_found self.content_type = 'text/plain' self.response_body = '' end end end

http://socialmemorycomplex.net/2010/06/02/gridfs-with-mongoid-and-carrierwave-on-rails-3/ Sunday, December 5, 2010
slide-62
SLIDE 62

ActionMailer

Sunday, December 5, 2010
slide-63
SLIDE 63

$ rails Usage: rails COMMAND [ARGS] The most common rails commands are: generate Generate new code (short-cut alias: "g") console Start the Rails console (short-cut alias: "c") server Start the Rails server (short-cut alias: "s") dbconsole Start a console for database in config/database.yml (short-cut alias: "db") new Create a new Rails application. "rails new my_app" creates a new application called MyApp in "./my_app" In addition to those, there are: application Generate the Rails application code destroy Undo code generated with "generate" benchmarker See how fast a piece of code runs profiler Get profile information from a piece of code plugin Install a plugin runner Run a piece of code in the application environment

Sunday, December 5, 2010
slide-64
SLIDE 64 OBIE FERNANDEZ

The Rich Get Richer: RAILS 3

Upgrade Path?

  • Upgrade to 2.3.8 and Bundler
  • Try http://github.com/rails/rails_upgrade
  • Upgrade to 3.0.x
  • rails console working
  • rails console production working
  • (unit) tests or specs green
  • Cucumber (integration specs) green
Sunday, December 5, 2010
slide-65
SLIDE 65 Sunday, December 5, 2010
slide-66
SLIDE 66 Sunday, December 5, 2010
slide-67
SLIDE 67

Ryan Bigg

Rails 3 Documentation Project

MAKE YOUR DONATION AT

http://pledgie.com/ campaigns/14034

Sunday, December 5, 2010
slide-68
SLIDE 68

Q/A

Sunday, December 5, 2010
slide-69
SLIDE 69 KAES

THE RAILS

™ 3 WAY

THE RAILS

™ 3 WAY

Forewords by David Heinemeier Hansson, creator of Ruby on Rails and Yehuda Katz, Rails Core

OBIE FERNANDEZ

with DURRAN JORDAN, JON LARKOWSKI, XAVIER NORIA, and TIM POPE

A d d i s o n - W e s l e y P r o f e s s i o n a l R u b y S e r i e s FERNANDEZ ISBN-13: ISBN-10: 978-0-321-60166-7 0-321-60166-1 9 7 8 0 3 2 1 6 0 1 6 6 7 5 4 9 9 9 $49.99 U.S. | $59.99 CANADA Cover design by Chuti Prasertsith Cover photograph by Grant Faint/Getty Images Inc. ext printed on recycled paper P R O G RAMM IN G / RU B Y O N RA IL S The Bible for Ruby on Rails Application Development y on Rails strips complexity from the development process, enabling professional developers to focus on what matters most: delivering business value via clean and maintainable code. The Rails™ 3 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 3. Pioneering Rails expert Obie Fernandez and a team of leading experts illuminate the entire Rails 3 API, along with the idioms, design approaches, and libraries that make developing applications with Rails so powerful. wing on their unsurpassed experience and track record, they address the real challenges development teams face, showing how to use Rails 3 to maximize your productivity. Using numerous detailed code examples, the author systematically covers Rails 3 key capabilities and subsystems, making this book a reference that you will turn to again and again. He presents advanced Rails programming techniques that have been proven effective in day-to-day usage on dozens of production Rails systems and offers important insights into behavior-driven development and production considerations such as scalability. Dive deep into the Rails 3 codebase and discover why Rails is designed the way it is—and how to make it do what you want it to do. This book will help you
  • Learn what’s new in Rails 3
  • Increase your productivity as a web application developer
  • Realize the overall joy in programming with Rails
  • Leverage Rails’ powerful capabilities for building REST-compliant APIs
  • Drive implementation and protect long-term maintainability using RSpec
  • Design and manipulate your domain layer using Active Record
  • Understand and program complex program flows using Action Controller
  • Master sophisticated URL routing concepts
  • Use Ajax techniques via Rails 3 support for unobtrusive JavaScript
  • Learn to extend Rails with popular gems and plugins, and how to
write your own
  • Extend Rails with the best third-party plug-ins and write your own
  • Integrate email services into your applications with Action Mailer
  • Improve application responsiveness with background processing
  • Create your own non-Active Record domain classes using Active Model
  • Master Rails’ utility classes and extensions in Active Support
mit.com/ruby “The Rails 3 Way is a comprehensive resource that digs into the new features in Rails 3 and perhaps more importantly, the rationale behind them.” —YEHUDA KATZ, Rails Core OBIE FERNANDEZ has been hacking computers since he got his first Commodore VIC-20 in the eighties, and found himself in the right place and time as a programmer on some of the first Java enterprise projects of the mid-nineties. Obie has been evangelizing Ruby on Rails online via blog posts and publications since early 2005. He has traveled around the world relentlessly promoting Rails at large industry conferences. As CEO and Founder of Hashrocket, Obie specializes in orchestrating the creation of large-scale, web-based applications, both for startups and mission-critical enterprise projects. He still gets his hands dirty with code on at least a weekly basis and posts regularly on various topics to his popular technology blog.
  • biefernandez.com
hashrocket.com tr3w.com Sunday, December 5, 2010
slide-70
SLIDE 70

HASHROCKET

EXPERTLY CRAFTED WEB

Thank you

  • bie@hashrocket.com

Obie Fernandez

Sunday, December 5, 2010