What's new in Rails 2?

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

4 comments

Comments 1 - 4 of 4 previous next Post a comment

  • guest8abf92 guest8abf92 11 months ago
    Rails 2 seems like a huge leap backwards overall... maybe it's just the convoluted style of the presentation but there just seems to be a lot of pointless chatter with no real establishment of what exactly is going on... title, code, title, code, cute picture, title, code... without a more definitive assessments of the values it really looks like these new additives are quite convoluted and poorly engineered...
  • millisami millisami 2 years ago
    I downloaded this ppt file and when I try to open via MS Powerpoint 2007, the PP opens but the file contents isn't shown at all.
    Does the downloaded file support MS 2007???
  • juarezpaf Juarez P. a. filho 2 years ago
    Unfortunately the slideshow importer crash some parts of presentation. I suggest read the slides in PDF form also.
    I'm a enthusiast at Rails' World and this new version seems like very great.
    I'll try test this new version soon in a project that I need develop.
    Thanks Bryan to excellent explanation about Rails 2.

  • brynary brynary 2 years ago
    The SlideShow importer choked on my syntax-highlighted code samples. Check out the full thing (in PDF form) at http://www.brynary.com/2007/12/12/what-s-new-in-rails-2-s...

Post a comment
Embed Video
Edit your comment Cancel

Notes on slide 1

Can everyone hear me? 40% as good as PHP.

35 Favorites

What's new in Rails 2? - Presentation Transcript

  1. What’s new in Rails 2?
    • Bryan Helmkamp
    • http://brynary.com /
  2. “Look at all the things I’m NOT doing.”
    • –DHH during the “Creating a blog
    • in 15 minutes” screencast
  3. Evolutionary, not revolutionary.
  4. ActiveRecord
  5. Numerical validation
    • Gains the ability to specify comparisons.
    • Examples:
    • validates_numericality_of :salary , :greater_than => 49_000
    • validates_numericality_of :age , :less_than_or_equal => 99
    • validates_numericality_of :employees , :greater_than => 0
  6. :allow_blank => true
    • Skips validation for empty strings and nil.
  7. XML in, JSON out
    • >> Post.new .from_xml ({:title => "Hello!", :body => "text"}.to_xml)
    • => #<Post id: nil, title: &quot;Hello!&quot;, body: &quot;text&quot;, created_at: nil, updated_at: nil>
    • >> Post.new(:title => &quot;Hello!&quot;, :body => &quot;text&quot;) .to_json
    • => &quot;{&quot;updated_at&quot;: null, &quot;title&quot;: &quot;Hello!&quot;, &quot;body&quot;: &quot;text&quot;, &quot;created_at&quot;: null}&quot;
  8. Sexy migrations
    • create_table :posts do | t |
    • t.belongs_to :blog , :null => false
    • t.string :title , :subtitle
    • t.text :body
    • t.timestamps
    • end
  9. Query cache
    • Very dumb. Checks SQL string equality.
    • Cleared by any INSERT/UPDATE/DELETE.
    • Enabled per-action by default.
    • Can be skipped if necessary:
    • def self.uncached_newest
    • uncached do
    • find( :all , :order => :created_at )
    • end
    • end
  10. Foxy Fixtures
  11. Three main features
    • Don’t specify the IDs for each record.
    • Reference associated fixtures by name.
    • Sets created_at and updated_at to Time.now automatically.
  12. Foxy Fixtures example
    • # blogs.yml
    • my_blog:
    • name: &quot;My awesome blog&quot;
    • # posts.yml
    • first_post:
    • blog: my_blog
    • title: &quot;First post!&quot;
  13. fixtures :all
    • Load all fixtures for all test cases. (Recommended!)
  14. ActionPack
  15. Cookie sessions
    • Now the default session store.
    • Stored in clear text, secured with a hash.
    • Configure a secret in environment.rb:
    • Rails :: Initializer .run do | config |
    • config.action_controller.session = {
    • :session_key => '_rails_app_session',
    • :secret => 'e96a9......aef9111a'
    • }
    • end
  16. HTTP-only cookies
    • Prevents access to cookies from JavaScript.
  17. CSRF protection
    • Enabled by default in application.rb
    • Uses a token to verify requests are from the application, not a malicious site.
    • Built-in to form_tag and friends.
  18. Partial layouts
    • Use with partials:
    • <% render :partial => &quot;post&quot;, :layout => &quot;window&quot; %>
    • or with a block:
    • <% render :layout => &quot;window&quot;, :locals => { :name => &quot;Recent&quot; } do %>
    • <% for post in @recent_posts %>
    • <h2> <%=h post.title %> </h2>
    • <!-- ... -->
    • <% end %>
    • <% end %>
  19. Route namespaces
    • map.namespace :admin do | admin |
    • # Maps to Admin::PostsController
    • admin.resources :posts
    • end
    • # Maps to PostsController
    • map.resources :posts
  20. Semicolon is dead. Long live forward slash! Long live forward slash!
  21. Association routing shortcuts
    • map.resources :blogs , :has_many => [ :posts , :themes ],
    • :has_one => :owner
  22. HTTP authentication
    • class PostsController < ApplicationController
    • USER_NAME , PASSWORD = &quot;bryan&quot;, &quot;secret&quot;
    • before_filter :authenticate , :except => [ :index ]
    • ...
    • private
    • def authenticate
    • authenticate_or_request_with_http_basic do | user_name , password |
    • user_name == USER_NAME && password == PASSWORD
    • end
    • end
    • end
  23. Exception handlers
    • class ApplicationController < ActionController::Base
    • rescue_from User :: NotAuthorized , :with => :deny_access
    • rescue_from 'MyAppError::Base' do | exception |
    • render :xml => exception.to_xml, :status => 500
    • end
    • protected
    • def deny_access
    • # ...
    • end
    • end
  24. Asset caching
    • Concatenates file contents.
    • Only active in production mode.
    • Examples:
    • <%= stylesheet_link_tag &quot;reset&quot;, &quot;main&quot;, :cache => true %>
    • <%# Cache in public/javascripts/special.js %>
    • <%= javascript_include_tag &quot;whiz&quot;, &quot;bang&quot;, :cache => &quot;special&quot; %>
  25. Asset servers
    • Distributes request to four asset hosts.
    • Speeds up page load time considerably.
    • In production.rb:
    • ActionController :: Base .asset_host = &quot;asset%d.example.com&quot;
  26. AtomFeedHelper
    • # index.atom.builder:
    • atom_feed do | feed |
    • feed.title(&quot;Bryan's Bytes&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')
    • entry.author do | author |
    • author.name(&quot;NYC.rb&quot;)
    • end
    • end
    • end
    • end
  27. Multiview
    • Template filename changes:
      • filename .format.renderer
    • Examples:
      • show.csv.erb
      • edit.html.haml
      • index.atom.builder
  28. simply_helpful
    • Now in core... but you should’ve been using it already.
  29. dom_class and dom_id
    • dom_class(@person) => &quot;person&quot;
    • dom_class(Person) => &quot;person&quot;
    • dom_class(@person, :edit) => &quot;edit_person&quot;
    • dom_id(@person) => &quot;person_1234&quot;
    • dom_id(Person.new) => &quot;new_person&quot;
  30. div_for/content_tag_for
    • <% div_for @person do %>
    • <!-- ... -->
    • <% end %>
    • <!-- Becomes -->
    • <div class=&quot;person&quot; id=&quot;person_42&quot;>
    • <!-- ... -->
    • </div>
  31. url_for for models
    • url_for(@post) works like post_path(@post).
    • url_for(Post.new) works like new_post_path.
    • Works with link_to, redirect_to, etc.
  32. render :partial for AR
    • render :partial => @post works like render :partial => &quot;post&quot;, :object => @post
    • render :partial => @posts works like render :partial => &quot;post&quot;, :collection => @posts
  33. form_for
    • Determines form action based on the record. (e.g. post_path or new_post_path)
    • New records use :method => :post
    • Existing records use :method => :put
    • Automatically adds a HTML class and ID
  34. form_for example
    • <% form_for @person do | f | %>
    • <%= f.text_field :name %>
    • <% end %>
    • <!-- Becomes -->
    • <form action=&quot;/people&quot; method=&quot;post&quot; class=&quot;person&quot; id=&quot;new_person&quot;>
    • <input type=&quot;text&quot; name=&quot;person[name]&quot; id=&quot;person_name&quot; />
    • </form>
  35. Extra Goodies
  36. Debugging
  37. Getting started
    • sudo gem install -y ruby-debug
    • Call the method “debugger” in your code
    • script/server --debugger
  38. Debugger commands
    • irb – Drop into an irb session
    • list – List the code surround the breakpoint
    • p/pp – Print results of an expression
    • up – Move one frame higher
    • cont – Resume execution
    • next/step – Execute one line at a time.
    • where – Display the current stack
  39. Live demo
  40. assert_emails
    • # Assert one email is sent during action
    • assert_emails 1 do
    • post :signup , :name => &quot;Bryan&quot;
    • end
    • # Assert no emails are sent
    • post :signup , :name => &quot;&quot;
    • assert_no_emails
  41. Hash filtering
    • Hash#except is the inverse of Hash#slice.
    • Example:
    • >> {:foo => 1, :bar => 2}.except(:bar, :baz)
    • => {:foo=>1}
  42. Database Rake tasks
    • rake db:create and db:create:all
    • rake db:drop and db:drop:all
    • rake db:reset
    • rake db:rollback (defaults to STEP=1)
    • rake db:version
  43. List routes with Rake
    • $ rake routes
    • posts GET /posts {:controller=>&quot;posts&quot;, :action=>&quot;index&quot;}
    • formatted_posts GET /posts.:format {:controller=>&quot;posts&quot;, :action=>&quot;index&quot;}
    • POST /posts {:controller=>&quot;posts&quot;, :action=>&quot;create&quot;}
    • POST /posts.:format {:controller=>&quot;posts&quot;, :action=>&quot;create&quot;}
    • new_post GET /posts/new {:controller=>&quot;posts&quot;, :action=>&quot;new&quot;}
    • formatted_new_post GET /posts/new.:format {:controller=>&quot;posts&quot;, :action=>&quot;new&quot;}
    • edit_post GET /posts/:id/edit {:controller=>&quot;posts&quot;, :action=>&quot;edit&quot;}
    • formatted_edit_post GET /posts/:id/edit.:format {:controller=>&quot;posts&quot;, :action=>&quot;edit&quot;}
    • post GET /posts/:id {:controller=>&quot;posts&quot;, :action=>&quot;show&quot;}
    • formatted_post GET /posts/:id.:format {:controller=>&quot;posts&quot;, :action=>&quot;show&quot;}
    • PUT /posts/:id {:controller=>&quot;posts&quot;, :action=>&quot;update&quot;}
    • PUT /posts/:id.:format {:controller=>&quot;posts&quot;, :action=>&quot;update&quot;}
    • DELETE /posts/:id {:controller=>&quot;posts&quot;, :action=>&quot;destroy&quot;}
    • DELETE /posts/:id.:format {:controller=>&quot;posts&quot;, :action=>&quot;destroy&quot;}
    • /:controller/:action/:id
    • /:controller/:action/:id.:format
  44. Initializer hooks
    • Rails load order:
    • config/preinitializer.rb
    • config/environment.rb
    • config/environments/RAILS_ENV.rb
    • config/initializers/*.rb
  45. Code annotations
    • Finds FIXME, TODO and OPTIMIZE comments.
    • $ rake notes
    • app/models/post.rb:
    • * [ 2] [TODO] : Add support for themes
    • app/views/layouts/application.rhtml:
    • * [ 1] [FIXME] Will break with less than three posts
  46. Request profiler
    • sudo gem install -y ruby-prof
    • Example:
    • $ cat login_session.rb
    • get_with_redirect '/'
    • post_with_redirect '/sessions', :password => 'NYC.rb!'
    • $ ./script/performance/request -n 10 login_session.rb
  47. Losing weight
  48. ActionWebService is out. Use ActiveResource for REST. Use ActiveResource for REST.
  49. acts_as_* behaviors
    • script/plugin install http://svn.rubyonrails.org/rails/plugins/acts_as_list/
    • script/plugin install http://svn.rubyonrails.org/rails/plugins/acts_as_nested_set/
    • script/plugin install http://svn.rubyonrails.org/rails/plugins/acts_as_tree/
  50. Controller variables
    • Don’t use @params, @session, @flash, @request or @env.
    • Just drop the “@” and use the methods.
  51. ActiveRecord finders
    • Post.find_all becomes Post.find(:all).
    • Post.find_first becomes Post.find(:first).
  52. Components
    • Interesting feature, but too slow .
    • Try refactoring to partials and filters...
    • ...or grab Sebastian Delmont’s plugin:
    • http://dev.notso.net/svn/rails/plugins/embedded_actions/trunk/
  53. Renamed routes
    • Nested resources now use the parent name as a prefix.
    • Example:
    • map.resources :blogs do | blog |
    • blog.resources :posts
    • end
    • post_path becomes blog_ post_path, etc.
  54. Pagination
    • Switch to will_paginate (recommended).
    • http://errtheblog.com/posts/56-im-paginating-again
    • Or install the classic_pagination plugin:
    • script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination
  55. Database adapters
    • Adapters except SQLite, MySQL and PostgreSQL were removed from Rails core.
    • sudo gem install activerecord- oracle -adapter
  56. Form helpers
    • start_form_tag and end_form_tag are gone.
    • Switch to the form_tag block syntax.
    • Use form_for when possible.
  57. form_tag example
    • <%= start_form_tag posts_path %>
    • <%= text_field :post , :title %>
    • <%= end_form_tag %>
    • becomes
    • <% form_tag posts_path do %>
    • <%= text_field :post , :title %>
    • <% end %>
  58. AJAX view helpers
    • Autocomplete and in-place editing moved to plugins.
    • script/plugin install http://svn.rubyonrails.org/rails/plugins/auto_complete/
    • script/plugin install http://svn.rubyonrails.org/rails/plugins/in_place_editing/
  59. “Use the Source, Luke.”
  60. How to upgrade
    • Upgrade to Rails 1.2.6.
    • Eliminate deprecation warnings.
    • Make sure all your tests pass.
    • Upgrade to Rails 2.0.1.
    • Run Mislav’s Rails 2 compatibility checker script. ( http://pastie.caboo.se/private/krcevozww61drdeza13e3a )
    • Make sure all your tests pass.
  61. Questions? What’s new in Rails 2? Bryan Helmkamp http://brynary.com / / / /
    • http://www.flickr.com/photos/kaufman/81616562/
    • http://icanhascheezburger.com/2007/01/12/wait-ill-fix-it/
    Photos used

brynarybrynary, 2 years ago

custom

20732 views, 35 favs, 13 embeds more stats

An overview of the major new features and changes i more

More Info

© All Rights Reserved

Go to text version
  • Total Views 20732
    • 20627 on SlideShare
    • 105 from embeds
  • Comments 4
  • Favorites 35
  • Downloads 757
Most viewed embeds
  • 36 views on http://www.informatik-student.de
  • 35 views on http://railsfs.blogspot.com
  • 19 views on http://cntt.tv
  • 3 views on http://peleqe2.forogratis.es
  • 3 views on http://www.dmitvn.com

more

All embeds
  • 36 views on http://www.informatik-student.de
  • 35 views on http://railsfs.blogspot.com
  • 19 views on http://cntt.tv
  • 3 views on http://peleqe2.forogratis.es
  • 3 views on http://www.dmitvn.com
  • 2 views on http://www.filescon.com
  • 1 views on http://gmodules.com
  • 1 views on file://
  • 1 views on http://www.rapidsharefast.com
  • 1 views on http://www.sadavi.com.vn
  • 1 views on http://funwithprogramming.blogspot.com
  • 1 views on http://simplesideias.com.br
  • 1 views on http://maxschulze.tumblr.com

less

Flagged as inappropriate Flag as inappropriate
Flag as innappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel

Categories