Migration from Rails 2 to Rails 3                      Abdullah Muhammad                           Haseeb Ahmad           ...
Table of ContentsIntroduction to the New features in Rails 3Differences between Rails 2 and Rails 3Migration of Rails 2 ap...
Core New FeaturesRails 3.0Brand new routerExplicit dependency management with BundlerRails 3.1Reversible MigrationsAssets ...
Rails 3.0Brand new router       Routes defined by each application are now name spaced within your Application module     ...
Rails 3.0 Contdendency management with Bundler uses a Gemfile in the application root to determine the gems you require   ...
Rails 3.1 line  or compress JavaScript and CSS assets ript files into one master.js file and all CSS files   into one mast...
Rails 3.1 Contdery as the default JavaScript library    jQuery is the default JavaScript library that ships with Rails 3.1...
Rails 3.2 atic Query Explains comes with a nice feature that explains queries generated by ARel by defining an explain met...
Differencesold scripts        new hotnessscript/generate      rails gscript/console       rails cscript/server        rail...
New Router APImap.resources :posts do |post|       post.resources :comments endresources :posts do       resources :commen...
ActionController - respond_withclass UsersController < ApplicationControllerdef index        @users = User.allrespond_to d...
Model@posts = Post.find(:all, :conditions => {:published => true} , :limit => 10)@posts = Post.where(:published => true).l...
Model Contd@published = Post.published@unpublished = Post.unpublishedclass Post < ActiveRecord::Base default_scope :order ...
Action ViewCross-Site Scripting (XSS)<%= h @post.body %><%= raw @post.body %><%= link_to_remote Show, :url => post %><a hr...
Deprecated Methodslink_to_remote      # link_to "Somewhere", /posts/1, :remote => true# <a href="/posts/1" data-remote="tr...
Migration from Rails2 to Rails3rvm install 1.9.2rvm use 1.9.2@Rails3 --creatervm gemset listgem install rails -v=3.1.3scri...
Upcoming SlideShare
Loading in …5
×

Migration from Rails2 to Rails3

1,490 views
1,376 views

Published on

Introduction of Rails 3
Differences between Rails 2 and Rails 3
Migration

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

  • Be the first to like this

No Downloads
Views
Total views
1,490
On SlideShare
0
From Embeds
0
Number of Embeds
85
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Migration from Rails2 to Rails3

  1. 1. Migration from Rails 2 to Rails 3 Abdullah Muhammad Haseeb Ahmad Nadeem Yasin Umair Amjad
  2. 2. Table of ContentsIntroduction to the New features in Rails 3Differences between Rails 2 and Rails 3Migration of Rails 2 app to Rails 3
  3. 3. Core New FeaturesRails 3.0Brand new routerExplicit dependency management with BundlerRails 3.1Reversible MigrationsAssets PipelinejQuery as the default JavaScript libraryRails 3.2Faster Development ModeNew Routing EngineAutomatic Query ExplainsTagged Logging
  4. 4. Rails 3.0Brand new router Routes defined by each application are now name spaced within your Application module Instead of We useActionController::Routing::Routes.draw do |map| AppName::Application.routes do map.resources :posts resources :postsend end1. Added match method to the routermatch "/main/:id", :to => "main#home"2. Added scope method to the router, allowing you to namespace routes for different languages or different actionsscope es do resources :projects, :path_names => { :edit => cambiar }, :path => proyectoend# Gives you the edit action with /es/proyecto/1/cambiar3. Added constraints method to the router, allowing you to guard routers with defined constraints. match "/foo/bar", :to => "foo#bar", :constraints => {:subdomain => "support"}4. Added root method to the router as a short cut for match ‘/’, :to => path.root :to => "foo#bar"The old style map commands still work as before with a backwards compatibility layer, however this will be removed in the 3.1 release.
  5. 5. Rails 3.0 Contdendency management with Bundler uses a Gemfile in the application root to determine the gems you require for your application to start.s processed by the Bundler, which then installs all your dependenciesem is dead, long live bundler and their brother complained about Rails’ handling of vendored/bundled gems since config.gem was added m "RedCloth", :lib =>redcloth, :version=>">= 4.0"dCloth", ">= 4.0", :require =>redcloth create a Gemfile, you simply have to run "bundle" pack and youre done!
  6. 6. Rails 3.1 line or compress JavaScript and CSS assets ript files into one master.js file and all CSS files into one master.css file. hitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a vel languageSS, CoffeeScript for JavaScript, and ERB for both by default.mpressed and minified by one central library, Sprockets. It is enabled by default. It can be disabled in con like fingerprinting at production environment
  7. 7. Rails 3.1 Contdery as the default JavaScript library jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it’s simple to switch. $ rails new myapp -j prototype Prototype are no longer vendored and is provided from now on by the prototype-rails gems.versible Migrations Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations To use reversible migrations, just define the change method. class MyMigration < ActiveRecord::Migration change eate_table(:horses) do |t| .column :content, :text .column :remind_at, :datetimendde commands like remove_column cannot be reversed. If you care to define how to move up and down in these cases, you should define the up and down methods as be
  8. 8. Rails 3.2 atic Query Explains comes with a nice feature that explains queries generated by ARel by defining an explain method in ActiveRecord::Relation.mple, .order(:name).explainoad (0.6ms) SELECT "products".* FROM "products" ORDER BY name(0.1ms) EXPLAIN QUERY PLAN SELECT "products".* FROM "products" ORDER BY nameAIN for: SELECT "products".* FROM "products" ORDER BY namen0|0|0|SCAN TABLE products (~1000000 rows)n0|0|0|USE TEMP B-TREE FOR ORDER BYn Loggingnning a multi-user, multi-account application, it’s a great help to be able to filter the log by who did what ogging in Active Support helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such app
  9. 9. Differencesold scripts new hotnessscript/generate rails gscript/console rails cscript/server rails sscript/dbconsole rails db
  10. 10. New Router APImap.resources :posts do |post| post.resources :comments endresources :posts do resources :comments endNAMED ROUTESmap.connect login, :controller => session, :action => newmatch login => session#newLEGACY ROUTESmap.connect :controller/:action/:idmap.connect :controller/:action/:id.:formatmatch :controller(/:action(/:id(.:format))) map.root :controller => "users"root :to => "users#index"
  11. 11. ActionController - respond_withclass UsersController < ApplicationControllerdef index @users = User.allrespond_to do |format| format.html format.xml { render :xml => @users.to_xml }endend.....class UsersController < ApplicationControllerrespond_to :html, :xml, :jsondef index @users = User.allrespond_with(@users)end
  12. 12. Model@posts = Post.find(:all, :conditions => {:published => true} , :limit => 10)@posts = Post.where(:published => true).limit(10)Post.find(:all, :conditions => {:author => "Joe"}, :includes => :comments, :order => "title", :limit => 10)Post.where(:author => "Joe").include(:comments).order(:title).limit(10)REFACTOR@posts = Post.where(:published => true)@posts = @posts.order(params[:order])@posts = Post.where(:published => true).order(params[:order])
  13. 13. Model Contd@published = Post.published@unpublished = Post.unpublishedclass Post < ActiveRecord::Base default_scope :order => title named_scope :published, :conditions => {:published => true} named_scope :unpublished, :conditions => {:published => false}endclass Post < ActiveRecord::Base default_scope order(title) scope :published, where(:published => true) scope :unpublished, where(:published => false)end
  14. 14. Action ViewCross-Site Scripting (XSS)<%= h @post.body %><%= raw @post.body %><%= link_to_remote Show, :url => post %><a href="#" onclick="new Ajax.Request(/posts/1, {asynchronous:true,evalScripts:true, parameters:authenticity_token= +encodeURIComponent(9sk..44d)}); return false;">Show</a><%= link_to Show, post, :remote => true %><a href="/posts/1" data-remote="true">Show</a><% remote_form_for(@post) do |f| %><form action="/posts" class="new_post" id="new_post" method="post"onsubmit="new Ajax.Request(/posts, {asynchronous:true,evalScripts:true, parameters:Form.serialize(this)}); return false;"><% form_for(@post, :remote => true) do |f| %><form action="/posts" class="new_post" data-remote="true" id="new_post" method="post">
  15. 15. Deprecated Methodslink_to_remote # link_to "Somewhere", /posts/1, :remote => true# <a href="/posts/1" data-remote="true">Somewhere</a>remote_form_forobserve_fieldobserve_formform_remote_tagbutton_to_remotesubmit_to_remotelink_to_functionperiodically_call_remoteprototype_legacy_helperhttps://github.com/rails/prototype_legacy_helper
  16. 16. Migration from Rails2 to Rails3rvm install 1.9.2rvm use 1.9.2@Rails3 --creatervm gemset listgem install rails -v=3.1.3script/plugin install git://github.com/rails/rails_upgrade.gitrake rails:upgrade:checkrake rails:upgrade:backuprvm 1.9.2rails new . -d mysqlbundle installrails s

×