Migration from Rails2 to Rails3
Upcoming SlideShare
Loading in...5
×
 

Migration from Rails2 to Rails3

on

  • 1,296 views

Introduction of Rails 3

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

Statistics

Views

Total Views
1,296
Views on SlideShare
1,243
Embed Views
53

Actions

Likes
0
Downloads
16
Comments
0

4 Embeds 53

http://thinkinglearningsharing.blogspot.com 50
http://thinkinglearningsharing.blogspot.com.au 1
http://www.slashdocs.com 1
http://thinkinglearningsharing.blogspot.de 1

Accessibility

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Migration from Rails2 to Rails3 Migration from Rails2 to Rails3 Presentation Transcript

    • Migration from Rails 2 to Rails 3 Abdullah Muhammad Haseeb Ahmad Nadeem Yasin Umair Amjad
    • Table of ContentsIntroduction to the New features in Rails 3Differences between Rails 2 and Rails 3Migration of Rails 2 app to Rails 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
    • 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.
    • 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!
    • 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
    • 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
    • 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
    • Differencesold scripts new hotnessscript/generate rails gscript/console rails cscript/server rails sscript/dbconsole rails db
    • 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"
    • 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
    • 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])
    • 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
    • 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">
    • 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
    • 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