Your SlideShare is downloading. ×
0
Upgrading to
                          Rails 3
 OSCON 2010
Thursday, July 22, 2010
Michael Bleigh
                 @mbleigh

 OSCON 2010
Thursday, July 22, 2010
Thursday, July 22, 2010
Jeremy McAnally’s
                          Rails Upgrade Handbook
                             bit.ly/railsupgrade
 OSCON...
Rails 3 is
                          Different
 OSCON 2010
Thursday, July 22, 2010
Rails 3 is a
                          Bi     ange
 OSCON 2010
Thursday, July 22, 2010
Why the hell
                    should I bother?

 OSCON 2010
Thursday, July 22, 2010
Modularity

 OSCON 2010
Thursday, July 22, 2010
Rails 2.3 Stack
                               ActiveRecord


                               ActiveSupport


             ...
Rails 3 Ecosystem
                                          DataMapper
                           ActiveRecord            ...
Rails 2.3 Controller

                          ActionController::Base


                          ApplicationController

...
Rails 3 Controller
                              AbstractController::Base


                              ActionController...
Less Monkeypatching



 OSCON 2010
Thursday, July 22, 2010
Security
   darwinbell via Flickr

 OSCON 2010
Thursday, July 22, 2010
small change,
                          big impact

 OSCON 2010
Thursday, July 22, 2010
HTML is escaped
                            by default.


 OSCON 2010
Thursday, July 22, 2010
<!-- Rails 2.3 -->
                  <div class='comment'>
                    <%= comment.body %>
                  </div...
It’s a good   thing.TM




 OSCON 2010
Thursday, July 22, 2010
New Apis

 OSCON 2010
Thursday, July 22, 2010
e Router

 OSCON 2010
Thursday, July 22, 2010
Rack Everywhere!


 OSCON 2010
Thursday, July 22, 2010
Fancy New DSL


 OSCON 2010
Thursday, July 22, 2010
More Powerful

 OSCON 2010
Thursday, July 22, 2010
# Rails 2.3
                  map.connect '/help', :controller => 'pages',
                                       :action ...
# Rails 2.3
                  with_options :path_prefix => 'admin',
                               :name_prefix => 'admin'...
# Rails 3

                  constraints(:subdomain => 'api') do
                    resources :statuses
                 ...
A ionMailer

 OSCON 2010
Thursday, July 22, 2010
It’s (mostly) just
                       a controller.

 OSCON 2010
Thursday, July 22, 2010
class Notifier < ActionMailer::Base
                    default :from => "mikel@example.org"

                    def welc...
class UsersController < ApplicationController
                    respond_to :html
                    def create
        ...
Bundler

 OSCON 2010
Thursday, July 22, 2010
Caution: Entering
                   Controversy

 OSCON 2010
Thursday, July 22, 2010
# Rails 2.3

                  # environment.rb
                  config.gem 'acts-as-taggable-on'
                  confi...
Dependency
                           Resolver

 OSCON 2010
Thursday, July 22, 2010
A iveRelation

 OSCON 2010
Thursday, July 22, 2010
Like named scopes,
                     only more so.


 OSCON 2010
Thursday, July 22, 2010
# Rails 2.3

                  Book.all(
                    :conditions => {:author => "Chuck Palahniuk"},
              ...
Inherently
                          Chainable

Thursday, July 22, 2010
# Rails 3

                  def index
                    @books = Book.where(:author => params[:author])
               ...
# Rails 2.3

                  class Book
                    named_scope :written_by {|a| {:conditions => {:author => a}}...
Be er H ks

 OSCON 2010
Thursday, July 22, 2010
Generators

 OSCON 2010
Thursday, July 22, 2010
config.generators do   |g|
                    g.orm                :mongomapper
                    g.test_framework     ...
Engines

 OSCON 2010
Thursday, July 22, 2010
#lib/your_plugin/engine.rb
                  require "your_plugin"
                  require "rails"

                  mo...
Lots more...
                     railsdispatch.com
                 edgeguides.rubyonrails.org



 OSCON 2010
Thursday, J...
But we’re already
                     on Rails 2.3!

 OSCON 2010
Thursday, July 22, 2010
How do we cope?


 OSCON 2010
Thursday, July 22, 2010
Ignore it all
                           and cheat.
                          github.com/rails/
                          ...
Finds Key
                           Blockers:
                          Routes, Bundler,
                           appli...
3 Step Process

 OSCON 2010
Thursday, July 22, 2010
Analyze Your App
                 rake rails:upgrade:check




 OSCON 2010
Thursday, July 22, 2010
Backup 2.3 Files
                 rake rails:upgrade:backup




 OSCON 2010
Thursday, July 22, 2010
Run Upgrades
                  rake rails:upgrade:routes
                  rake rails:upgrade:gems
                  rake ...
Takeaways

 OSCON 2010
Thursday, July 22, 2010
Tests help.
                    Unfortunately, they
                       may not run.


Thursday, July 22, 2010
Don’t be afraid to
                            re-generate.


Thursday, July 22, 2010
Just take it one
                          problem at a time.


Thursday, July 22, 2010
estions?
                          @mbleigh   @intridea
                 github.com/mbleigh/upgrade-to-rails3


 OSCON 2010...
Upcoming SlideShare
Loading in...5
×

Upgrading to Rails 3

5,057

Published on

Slides from my OSCON 2010 talk "Upgrading to Rails 3". For more information including a livecoding session of upgrading a simple Rails app from 2.3 to 3, visit http://bit.ly/rails-upgrade-talk

Published in: Technology
1 Comment
7 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,057
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
111
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "Upgrading to Rails 3"

  1. 1. Upgrading to Rails 3 OSCON 2010 Thursday, July 22, 2010
  2. 2. Michael Bleigh @mbleigh OSCON 2010 Thursday, July 22, 2010
  3. 3. Thursday, July 22, 2010
  4. 4. Jeremy McAnally’s Rails Upgrade Handbook bit.ly/railsupgrade OSCON 2010 Thursday, July 22, 2010
  5. 5. Rails 3 is Different OSCON 2010 Thursday, July 22, 2010
  6. 6. Rails 3 is a Bi ange OSCON 2010 Thursday, July 22, 2010
  7. 7. Why the hell should I bother? OSCON 2010 Thursday, July 22, 2010
  8. 8. Modularity OSCON 2010 Thursday, July 22, 2010
  9. 9. Rails 2.3 Stack ActiveRecord ActiveSupport ActiveResource ActionPack Test::Unit OSCON 2010 Thursday, July 22, 2010
  10. 10. Rails 3 Ecosystem DataMapper ActiveRecord MongoMapper ActiveSupport ActiveResource ActiveModel ActionPack RSpec Bacon Test::Unit OSCON 2010 Thursday, July 22, 2010
  11. 11. Rails 2.3 Controller ActionController::Base ApplicationController YourController OSCON 2010 Thursday, July 22, 2010
  12. 12. Rails 3 Controller AbstractController::Base ActionController::Metal ActionController::Base ApplicationController YourController OSCON 2010 Thursday, July 22, 2010
  13. 13. Less Monkeypatching OSCON 2010 Thursday, July 22, 2010
  14. 14. Security darwinbell via Flickr OSCON 2010 Thursday, July 22, 2010
  15. 15. small change, big impact OSCON 2010 Thursday, July 22, 2010
  16. 16. HTML is escaped by default. OSCON 2010 Thursday, July 22, 2010
  17. 17. <!-- Rails 2.3 --> <div class='comment'> <%= comment.body %> </div> <!-- Rails 3 --> <div class="comment"> <%= comment.body.html_safe %> </div> <!-- Rails 3 (alternate) --> <div class="comment"> <%=raw comment.body %> </div> Thursday, July 22, 2010
  18. 18. It’s a good thing.TM OSCON 2010 Thursday, July 22, 2010
  19. 19. New Apis OSCON 2010 Thursday, July 22, 2010
  20. 20. e Router OSCON 2010 Thursday, July 22, 2010
  21. 21. Rack Everywhere! OSCON 2010 Thursday, July 22, 2010
  22. 22. Fancy New DSL OSCON 2010 Thursday, July 22, 2010
  23. 23. More Powerful OSCON 2010 Thursday, July 22, 2010
  24. 24. # Rails 2.3 map.connect '/help', :controller => 'pages', :action => 'help' # Rails 3 match '/help', :to => 'pages#help' # Rails 2.3 map.resources :users do |users| users.resources :comments end # Rails 3 resources :users do resources :comments end Thursday, July 22, 2010
  25. 25. # Rails 2.3 with_options :path_prefix => 'admin', :name_prefix => 'admin' do |admin| admin.resources :users admin.resources :posts end # Rails 3 namespace :admin resources :users resources :posts end Thursday, July 22, 2010
  26. 26. # Rails 3 constraints(:subdomain => 'api') do resources :statuses resources :friends end match '/hello', :to => lambda{ |env| [200, {'Content-Type' => 'text/plain'}, 'Hello World'] } match '/other-site', :to => redirect('http://url.com') Thursday, July 22, 2010
  27. 27. A ionMailer OSCON 2010 Thursday, July 22, 2010
  28. 28. It’s (mostly) just a controller. OSCON 2010 Thursday, July 22, 2010
  29. 29. class Notifier < ActionMailer::Base default :from => "mikel@example.org" def welcome_email(user) @name = user.name attachments['terms.pdf'] = File.read( Rails.root.join('docs/terms.pdf') ) mail(:to => user.email, :subject => "G’day Mate!") end end Thursday, July 22, 2010
  30. 30. class UsersController < ApplicationController respond_to :html def create @user = User.new(params[:user]) Notifier.welcome_email(@user).deliver if @user.save respond_with @user end end Thursday, July 22, 2010
  31. 31. Bundler OSCON 2010 Thursday, July 22, 2010
  32. 32. Caution: Entering Controversy OSCON 2010 Thursday, July 22, 2010
  33. 33. # Rails 2.3 # environment.rb config.gem 'acts-as-taggable-on' config.gem 'ruby-openid', :lib => false # test.rb config.gem 'rspec' config.gem 'cucumber' # Rails 3 # Gemfile gem 'acts-as-taggable-on' gem 'ruby-openid', :require => false group :test do gem 'rspec' gem 'cucumber' end Thursday, July 22, 2010
  34. 34. Dependency Resolver OSCON 2010 Thursday, July 22, 2010
  35. 35. A iveRelation OSCON 2010 Thursday, July 22, 2010
  36. 36. Like named scopes, only more so. OSCON 2010 Thursday, July 22, 2010
  37. 37. # Rails 2.3 Book.all( :conditions => {:author => "Chuck Palahniuk"}, :order => "published_at DESC", :limit => 10 ) # Rails 3 Book.where(:author => "Chuck Palahniuk") .order("published_at DESC").limit(10) Thursday, July 22, 2010
  38. 38. Inherently Chainable Thursday, July 22, 2010
  39. 39. # Rails 3 def index @books = Book.where(:author => params[:author]) if params[:author] @books = @books.order(:title) if params[:sort] == 'title' respond_with @books end Thursday, July 22, 2010
  40. 40. # Rails 2.3 class Book named_scope :written_by {|a| {:conditions => {:author => a}}} named_scope :after {|d| {:conditions => ["published_on > ?", d]}} # Rails 3 class Book class << self def written_by(name) where(:author => name) end def after(date) where(["published_on > ?", date]) end end end Thursday, July 22, 2010
  41. 41. Be er H ks OSCON 2010 Thursday, July 22, 2010
  42. 42. Generators OSCON 2010 Thursday, July 22, 2010
  43. 43. config.generators do |g| g.orm :mongomapper g.test_framework :rspec g.integration_tool :rspec end rails g model my_model Thursday, July 22, 2010
  44. 44. Engines OSCON 2010 Thursday, July 22, 2010
  45. 45. #lib/your_plugin/engine.rb require "your_plugin" require "rails" module YourPlugin class Engine < Rails::Engine engine_name :your_plugin end end Thursday, July 22, 2010
  46. 46. Lots more... railsdispatch.com edgeguides.rubyonrails.org OSCON 2010 Thursday, July 22, 2010
  47. 47. But we’re already on Rails 2.3! OSCON 2010 Thursday, July 22, 2010
  48. 48. How do we cope? OSCON 2010 Thursday, July 22, 2010
  49. 49. Ignore it all and cheat. github.com/rails/ rails_upgrade OSCON 2010 Thursday, July 22, 2010
  50. 50. Finds Key Blockers: Routes, Bundler, application.rb OSCON 2010 Thursday, July 22, 2010
  51. 51. 3 Step Process OSCON 2010 Thursday, July 22, 2010
  52. 52. Analyze Your App rake rails:upgrade:check OSCON 2010 Thursday, July 22, 2010
  53. 53. Backup 2.3 Files rake rails:upgrade:backup OSCON 2010 Thursday, July 22, 2010
  54. 54. Run Upgrades rake rails:upgrade:routes rake rails:upgrade:gems rake rails:upgrade:configuration OSCON 2010 Thursday, July 22, 2010
  55. 55. Takeaways OSCON 2010 Thursday, July 22, 2010
  56. 56. Tests help. Unfortunately, they may not run. Thursday, July 22, 2010
  57. 57. Don’t be afraid to re-generate. Thursday, July 22, 2010
  58. 58. Just take it one problem at a time. Thursday, July 22, 2010
  59. 59. estions? @mbleigh @intridea github.com/mbleigh/upgrade-to-rails3 OSCON 2010 Thursday, July 22, 2010
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×