Rails2 Pr

4,564 views

Published on

OSC2007-fall Rails2.0 Preview Release

Published in: Technology, Sports
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,564
On SlideShare
0
From Embeds
0
Number of Embeds
40
Actions
Shares
0
Downloads
163
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Rails2 Pr

  1. 1. • Rails 2.0 Preview Release • 1.2.4 • 2.0 •
  2. 2. Behold, behold, Rails 2.0 is almost here. But before we can slap on the final stamp, we’re going to pass through a couple of trial release phases. The first is this preview release, which allows you to sample the goodies in their almost finished state. • 2.0 • • • by DHH
  3. 3. We might change a few things or add something else, but by and large, this is how Rails 2.0 is going to look and feel. After this release have had a chance to be tried out, we’re going to move to a release candidate or two (or three, depending on how many we need). Then, the final release. • 2.0 • •
  4. 4. Before the release of 2.0, we’re also going to be putting out 1.2.4, which will include a variety of bug fixes and the last deprecation warnings to get you ready for upgrading an existing application to 2.0 standards. • 2.0 1.2.4 • • • 2.0 deprecation warning
  5. 5. Enough about process. Let me tell you a little bit about what’s new in Rails 2.0: • Rails 2.0
  6. 6. Action Pack: Resources • • namespace • rake routes routes •
  7. 7. Action Pack: Resources map.resources( :users, :has_many => :friends ) config/routes
  8. 8. Action Pack: Multiview # should go in config/initializers/mime_types.rb Mime.register_alias quot;text/htmlquot;, :iphone • respond_to class ApplicationController < ActionController::Base before_filter :adjust_format_for_iphone • show.rhtml private show.html.erb def adjust_format_for_iphone if request.env[quot;HTTP_USER_AGENTquot;] && request.env[quot;HTTP_USER_AGENTquot;][/(iPhone|iPod)/] • request.format = :iphone 3.0 show.rhtml deprecated end end • show.csv.erb text/csv CSV end class PostsController < ApplicationController def index respond_to do |format| • − format.html # renders index.html.erb format.iphone # renders index.iphone.erb end end end
  9. 9. Action Pack: Record identification # person is a Person object, which by convention will # be mapped to person_url for lookup redirect_to(person) link_to(person.name, person) form_for(person) • • URL • URL • :controller=>:user,:action=>:index • form_to(person) person (PUT) (POST) form action
  10. 10. Action Pack: HTTP Loving class PostsController < ApplicationController USER_NAME, PASSWORD = quot;dhhquot;, quot;secretquot; before_filter :authenticate, :except => [ :index ] • Basic ( ) def index render :text => quot;Everyone can see me!quot; end • javascript_include_tag def edit render :text => quot;I'm only accessible if you know (:all,:cache=>true) the passwordquot; end private public/javascripts/all.js def authenticate authenticate_or_request_with_http_basic do | user_name, password| user_name == USER_NAME && password == PASSWORD end end end
  11. 11. Action Pack: Security • form Ajax CSRF • XSS TextHelper#sanitize • HTTP only cookies
  12. 12. Action Pack: Exception handling class PostsController < ApplicationController rescue_from User::NotAuthorized, :with => :deny_access protected def deny_access ... end end • rescue_from
  13. 13. Action Pack: Miscellaneous • atom RSS # index.atom.builder: atom_feed do |feed| feed.title(quot;My great blog!quot;) feed.updated((@posts.first.created_at)) for post in @posts • feed.entry(post) do |entry| entry.title(post.title) entry.content(post.body, :type => 'html') • asset entry.author do |author| author.name(quot;DHHquot;) • end end • end in_place_editor end auto_complete_for Rails
  14. 14. Active Record: Performance • Query • fixture 50-100%
  15. 15. Active Record: Sexy migrations create_table :people do |t| t.column, quot;account_idquot;, :integer t.column, quot;first_namequot;, :string, :null => false t.column, quot;last_namequot;, :string, :null => false t.column, quot;descriptionquot;, :text t.column, quot;created_atquot;, :datetime t.column, quot;updated_atquot;, :datetime end create_table :people do |t| t.integer :account_id t.string :first_name, :last_name, :null => false t.text :description t.timestamps end
  16. 16. Active Record: XML in, JSON out • XML JSON Person.new.from_xml(“David“) person.to_json
  17. 17. Active Record: Shedding some weight acts_as_XYZ • ActiveRecord acts_as_XYZ Rails ./script/plugin install acts_as_list
  18. 18. Active Record: Shedding some weight DB • DB gem • activerecord-XYZ-adapter
  19. 19. Active Record: with_scope with a dash of syntactic vinegar • .with_scope public protected • • • .send(:with_scope) with_scope
  20. 20. ActionWebService out, ActiveResource in • SOAP vs REST • SOAP • ActionWebService gem • ActiveResource • ActiveResource ActiveRecord
  21. 21. ActiveSupport • • Array#rand • Hash#except • Date • assert_defference •
  22. 22. Action Mailer • • • assert_email
  23. 23. Rails: The debugger is back • ruby-debug • --debugger -u • ./script/breakpointer
  24. 24. Rails: Clean up your environment • inflections.rb • mime_types.rb mime type environment.rb config
  25. 25. Rails: Easier plugin order • acts_as_list • environment.rb config.plugins = [ :acts_as_list, :all ]
  26. 26. And hundreds upon hundreds of other improvements • CHANGELOG
  27. 27. • • basic • with_scope •

×