timothy n. tsvetkov, rails 3.1
DESCRIPTION
Timothy N. Tsvetkov & Gregory Mann's keynote on Rails 3.1 new features.TRANSCRIPT
Ruby NoName PodcastPropaganda sponsorship
Rails 3.1
Rails 3.12 years of development
1234 commits321 Contributors
243244 coffee caps1 dhh
Delivering DevelopersHappiness
HTTP Streaming
HTTP StreamingMake your’s applications even faster
Browser start processing CSS and JSbefore 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 end render :stream => true
<!DOCTYPE html><html><head> <title><%= yield :title %></title> ... ...</head><body>
<% content_for :title, "Projects" %>
<%= yield :title %>
<% content_for :title, "Projects" %>
<%= yield :title %>
<% content_for :title, "Projects" %>
@posts = Post.cool_posts
<%= yield :title %>
<% provide :title, "Projects" %>
@posts = Post.cool_posts
D’oh
Rack::Cache
Rack::Cache
Middlewares that need to manipulate the body
Middlewares that need to manipulate the body
1.9.2 Onlyfibers
ActiveRecord Identity Map
by Emilio Tagua
user1 = User.find(1) user2 = User.find(1)
user1 == user2 # => trueuser1.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.firstcomment.post = nilcomment.save
Post.destroy(@post.id)
Post.has_many :comments, :dependent => :destroy
comment = @post.comments.firstcomment.post = nilcomment.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 => :adminend
class Post < ActiveRecord::Base attr_accessible :title attr_accessible :title, :user_id, :as => :adminend
Post.update_attributes(params[:post], :as => :admin)
Callable in Scope
class Filter < Struct.new(:klass) def call(*args); endend
module CategoryFilter def call(category, *args) klass.where(:category => args.shift) super(*args) endend
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_tokencustom 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?