Timothy N. Tsvetkov, Rails 3.1
-
Upload
evil-martians -
Category
Documents
-
view
1.156 -
download
0
description
Transcript of Timothy N. Tsvetkov, Rails 3.1
![Page 1: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/1.jpg)
![Page 2: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/2.jpg)
![Page 3: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/3.jpg)
![Page 4: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/4.jpg)
Ruby NoName PodcastPropaganda sponsorship
![Page 5: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/5.jpg)
Rails 3.1
![Page 6: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/6.jpg)
Rails 3.12 years of development
1234 commits321 Contributors
243244 coffee caps1 dhh
![Page 7: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/7.jpg)
Delivering DevelopersHappiness
![Page 8: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/8.jpg)
HTTP Streaming
![Page 9: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/9.jpg)
HTTP StreamingMake your’s applications even faster
![Page 10: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/10.jpg)
Browser start processing CSS and JSbefore you request DB
![Page 11: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/11.jpg)
Yes, all DB requests actually in view
![Page 12: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/12.jpg)
Yes, all DB requests actually in view
But, who care?
![Page 13: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/13.jpg)
Unicorn
![Page 14: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/14.jpg)
listen 3000, :tcp_nopush => false
![Page 15: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/15.jpg)
class PostsController
![Page 16: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/16.jpg)
class PostsController stream
![Page 17: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/17.jpg)
class PostsController stream :only => :index
![Page 18: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/18.jpg)
class PostsController def index @posts = Post.cool_posts.all end
![Page 19: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/19.jpg)
class PostsController def index @posts = Post.cool_posts.all end render :stream => true
![Page 20: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/20.jpg)
<!DOCTYPE html><html><head> <title><%= yield :title %></title> ... ...</head><body>
<% content_for :title, "Projects" %>
![Page 21: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/21.jpg)
<%= yield :title %>
<% content_for :title, "Projects" %>
![Page 22: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/22.jpg)
<%= yield :title %>
<% content_for :title, "Projects" %>
@posts = Post.cool_posts
![Page 23: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/23.jpg)
<%= yield :title %>
<% provide :title, "Projects" %>
@posts = Post.cool_posts
![Page 24: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/24.jpg)
D’oh
![Page 25: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/25.jpg)
Rack::Cache
![Page 26: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/26.jpg)
Rack::Cache
![Page 27: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/27.jpg)
Middlewares that need to manipulate the body
![Page 28: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/28.jpg)
Middlewares that need to manipulate the body
![Page 29: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/29.jpg)
1.9.2 Onlyfibers
![Page 30: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/30.jpg)
ActiveRecord Identity Map
by Emilio Tagua
![Page 31: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/31.jpg)
user1 = User.find(1) user2 = User.find(1)
user1 == user2 # => trueuser1.object_id == user2.object_id # => true
![Page 32: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/32.jpg)
config.active_record.identity_map = true
![Page 33: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/33.jpg)
Does not track associations :(
![Page 34: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/34.jpg)
Post.has_many :comments, :dependent => :destroy
comment = @post.comments.firstcomment.post = nilcomment.save
Post.destroy(@post.id)
![Page 35: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/35.jpg)
Post.has_many :comments, :dependent => :destroy
comment = @post.comments.firstcomment.post = nilcomment.save
Post.destroy(@post.id)
comment will be destroyed
![Page 36: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/36.jpg)
Prepared Statements
![Page 37: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/37.jpg)
![Page 38: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/38.jpg)
SELECT * FROM users WHERE id = 42;
![Page 39: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/39.jpg)
SELECT * FROM users WHERE id = ?;
![Page 40: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/40.jpg)
Works Prefect• SQLite
• Postgres
Complicated
• MySQL
![Page 41: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/41.jpg)
Role-based mass-assignment
protection
![Page 42: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/42.jpg)
class Post < ActiveRecord::Base attr_accessible :title attr_accessible :title, :user_id, :as => :adminend
![Page 43: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/43.jpg)
class Post < ActiveRecord::Base attr_accessible :title attr_accessible :title, :user_id, :as => :adminend
Post.update_attributes(params[:post], :as => :admin)
![Page 44: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/44.jpg)
Callable in Scope
![Page 45: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/45.jpg)
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
![Page 46: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/46.jpg)
jQuery by default
![Page 47: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/47.jpg)
RJS has been extracted out to a gem
![Page 48: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/48.jpg)
force_ssl
![Page 49: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/49.jpg)
authenticity_tokencustom handling or to omit the token
![Page 50: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/50.jpg)
Deprecated
![Page 51: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/51.jpg)
AR options hash
:conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock
![Page 52: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/52.jpg)
green_items = Item.scoped_by_colour('orange')
![Page 53: Timothy N. Tsvetkov, Rails 3.1](https://reader031.fdocuments.us/reader031/viewer/2022013011/554bc7c6b4c90530298b56aa/html5/thumbnails/53.jpg)
Questions?