Timothy N. Tsvetkov, Rails 3.1

1,450 views

Published on

Timothy N. Tsvetkov & Gregory Mann's keynote on Rails 3.1 new features.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,450
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Timothy N. Tsvetkov, Rails 3.1

  1. 1. Ruby NoName Podcast Propaganda sponsorship
  2. 2. Rails 3.1
  3. 3. Rails 3.12 years of development 1234 commits 321 Contributors 243244 coffee caps 1 dhh
  4. 4. Delivering Developers Happiness
  5. 5. HTTP Streaming
  6. 6. HTTP StreamingMake your’s applications even faster
  7. 7. Browser startprocessing CSS and JSbefore you request DB
  8. 8. Yes, all DB requests actually in view
  9. 9. Yes, all DB requests actually in view But, who care?
  10. 10. Unicorn
  11. 11. listen 3000, :tcp_nopush => false
  12. 12. class PostsController
  13. 13. class PostsController stream
  14. 14. class PostsController stream :only => :index
  15. 15. class PostsController def index @posts = Post.cool_posts.all end
  16. 16. class PostsController def index @posts = Post.cool_posts.all render :stream => true end
  17. 17. <!DOCTYPE html><html><head> <title><%= yield :title %></title> ... ...</head><body><% content_for :title, "Projects" %>
  18. 18. <%= yield :title %><% content_for :title, "Projects" %>
  19. 19. <%= yield :title %> @posts = Post.cool_posts<% content_for :title, "Projects" %>
  20. 20. <%= yield :title %> @posts = Post.cool_posts<% provide :title, "Projects" %>
  21. 21. D’oh
  22. 22. Rack::Cache
  23. 23. Rack::Cache
  24. 24. Middlewares that needto manipulate the body
  25. 25. Middlewares that needto manipulate the body
  26. 26. 1.9.2 Only fibers
  27. 27. ActiveRecordIdentity Map by Emilio Tagua
  28. 28. user1 = User.find(1)user2 = User.find(1)user1 == user2 # => trueuser1.object_id == user2.object_id # => true
  29. 29. config.active_record.identity_map = true
  30. 30. Does not trackassociations :(
  31. 31. Post.has_many :comments, :dependent => :destroycomment = @post.comments.firstcomment.post = nilcomment.savePost.destroy(@post.id)
  32. 32. Post.has_many :comments, :dependent => :destroycomment = @post.comments.firstcomment.post = nilcomment.savePost.destroy(@post.id) comment will be destroyed
  33. 33. Prepared Statements
  34. 34. SELECT * FROM users WHERE id = 42;
  35. 35. SELECT * FROM users WHERE id = ?;
  36. 36. Works Prefect • SQLite • Postgres Complicated• MySQL
  37. 37. Role-basedmass-assignment protection
  38. 38. class Post < ActiveRecord::Base attr_accessible :title attr_accessible :title, :user_id, :as => :adminend
  39. 39. class Post < ActiveRecord::Base attr_accessible :title attr_accessible :title, :user_id, :as => :admin endPost.update_attributes(params[:post], :as => :admin)
  40. 40. Callable in Scope
  41. 41. class Filter < Struct.new(:klass) def call(*args); endendmodule CategoryFilter def call(category, *args) klass.where(:category => args.shift) super(*args) endendclass User < ActiveRecord::Base scope :combined, Filter.new(self).extend(NameFilter)end
  42. 42. jQuery by default
  43. 43. RJS has been extracted out to a gem
  44. 44. force_ssl
  45. 45. authenticity_token custom handling or to omit the token
  46. 46. Deprecated
  47. 47. AR options hash:conditions, :include, :joins,:limit, :offset, :order,:select, :readonly, :group,:having, :from, :lock
  48. 48. green_items = Item.scoped_by_colour(orange)
  49. 49. Questions?

×