Ruby NoName Podcast
     Propaganda sponsorship
Rails 3.1
Rails 3.1
2 years of development
    1234 commits
   321 Contributors
  243244 coffee caps
         1 dhh
Delivering Developers
      Happiness
HTTP Streaming
HTTP Streaming
Make your’s applications even faster
Browser start
processing CSS and JS
before you request DB
Yes, all DB requests
  actually in view
Yes, all DB requests
  actually in view
      But, who care?
Unicorn
listen 3000, :tcp_nopush => false
class PostsController
class PostsController
  stream
class PostsController
  stream :only => :index
class PostsController
 def index
   @posts = Post.cool_posts.all

 end
class PostsController
 def index
   @posts = Post.cool_posts.all
   render :stream => true
 end
<!DOCTYPE html>
<html>
<head>
  <title><%= yield :title %></title>
  ...
  ...
</head>
<body>



<% content_for :title, "Projects" %>
<%= yield :title %>




<% content_for :title, "Projects" %>
<%= yield :title %>




      @posts = Post.cool_posts




<% content_for :title, "Projects" %>
<%= yield :title %>




    @posts = Post.cool_posts




<% provide :title, "Projects" %>
D’oh
Rack::Cache
Rack::Cache
Middlewares that need
to manipulate the body
Middlewares that need
to manipulate the body
1.9.2 Only
   fibers
ActiveRecord
Identity Map
   by Emilio Tagua
user1 = User.find(1)
user2 = User.find(1)

user1 == user2 # => true
user1.object_id == user2.object_id # => true
config.active_record.identity_map = true
Does not track
associations :(
Post.has_many :comments, :dependent => :destroy

comment = @post.comments.first
comment.post = nil
comment.save

Post.destroy(@post.id)
Post.has_many :comments, :dependent => :destroy

comment = @post.comments.first
comment.post = nil
comment.save

Post.destroy(@post.id)




        comment will be
          destroyed
Prepared Statements
SELECT * FROM users WHERE id = 42;
SELECT * FROM users WHERE id = ?;
Works Prefect
 • SQLite
 • Postgres
          Complicated
• MySQL
Role-based
mass-assignment
  protection
class Post < ActiveRecord::Base
  attr_accessible :title
  attr_accessible :title, :user_id, :as => :admin
end
class Post < ActiveRecord::Base
   attr_accessible :title
   attr_accessible :title, :user_id, :as => :admin
 end




Post.update_attributes(params[:post], :as => :admin)
Callable in Scope
class Filter < Struct.new(:klass)
  def call(*args); end
end

module CategoryFilter
  def call(category, *args)
    klass.where(:category => args.shift)
    super(*args)
  end
end

class User < ActiveRecord::Base
  scope :combined, Filter.new(self).extend(NameFilter)
end
jQuery by default
RJS has been extracted
     out to a gem
force_ssl
authenticity_token
 custom handling or to omit the token
Deprecated
AR options hash

:conditions, :include, :joins,
:limit, :offset, :order,
:select, :readonly, :group,
:having, :from, :lock
green_items = Item.scoped_by_colour('orange')
Questions?

Timothy N. Tsvetkov, Rails 3.1