SlideShare une entreprise Scribd logo
1  sur  25
Rails 3
 (beta)
Roundup
  April 6, 2010
Why Upgrade
• Performance
  tighter & faster codebase, relational optimizations, shorter path to response, better scaling, better use of Rack & Middleware




• Security
  better routing DSL, XSS protection, more powerful controller stack, better use of Rack & Middleware, fixes




• Labour-savings
  easier routing, reliable gem management, easier Ajax, better code reuse, less monkey-patching, better & easier generators




• Modernization
  Rack reliance, later Ruby, plug in new frameworks and components, new standards




• Cost saving
  lower hardware requirements, less Gem maintenance, consistency means easier for developers
HTTP://GUIDES.RAILS.INFO/3_0_RELEASE_NOTES.HTML




                Significant Features
      • Dependency management with Bundler

      • More concise router

      • Chainable database query language

      • New ActionMailer API

      • Unobtrusive JavaScript

      • Better modularity

      • Improved XSS protection
Bundler
              http://railscasts.com/episodes/201-bundler

                                                         get used to version juggling for now


                           gem "rails", "3.0.0.beta"
• all gems listed in       # gem "rails", :git => "git://github.com/rails/
  Gemfile                   rails.git"

                           gem "sqlite3-ruby", :require => "sqlite3"

• ‘setup’ gemfile           # gem "rspec", :group => :test
                           group :test do
                             gem "webrat"
                           end
• ‘install’
                           gem install bundler
                           bundle setup
• ‘pack’                   bundle install
                           bundle unlock
                           mate Gemfile
                           bundle install --without=test
• deploy app               bundle pack


                           # application.rb

• unlock to modify         require 'rails/all'

                           Bundler.require(:default, Rails.env) if defined?(Bundler)



                                            Need version 9+. No config.gem required for Rails 3, although some need it for Rails 2.
New Modular
               Architecture
• “Railties framework is now a set of individual Railties, each
  inheriting from a new class, Rails::Railtie”

• Third-party plugins hook into early stages of initialization

• Rake tasks and generators part of the frameworks

• “In short, Rails frameworks are now plugins to Rails”

  Action Mailer * Action Pack * Active Record *
      Active Resource * Active Model * Active
                      Support
• And features like ActiveRecord validations and serialization
  reusable, eg: include ActiveModel::Validations
Routing
                   resources :products do  

• more concise      get :detailed, :on => :member 
                   end 
                          block
                   resources :forums do  

  DSL               collection do  
                      get :sortable  
                      put :sort 
                    end  
                    resources :topics

• rack routes      end

                   match "/secret" => "info#about", :constraints => { :user_agent => /Firefox/ }


                   constraints :host => /localhost/ do  

• constraints       match "/secret" => "info#about"  
                    match "/topsecret" => "info#about"  
                   end 

                   match "/hello" => proc { |env| [200, {}, "Hello Rack!"] }

• other features   root :to => "home#index"

                   match "/about" => "info#about", 
                    :as => :about
Controllers
•   taller stack abstracting
    rendering, layouts, rack,      AbstractController::Base
    etc
                                   ActionController::Metal
•   enhance by subclassing




                                                                    New
    relevant layer                  ActionController::Base




                                                              Old
•   middleware layer                ApplicationController

•   ‘respond_with(@post)’               MyController

•   flash[:notice] & flash[:alert]
ActionMailer
• like a controller            r g mailer UserMailer welcome

                                            gives...
• email types like
  actions               class UserMailer < ActionMailer::Base

                              def welcome(user, subdomain)
                                @user = user
• mail() to send                @subdomain = subdomain

                                mail(:from => "admin@testapp.com",
                                 :to => @user.email,
• no ‘deliver_’ prefix            :subject => "Welcome to TestApp")

                              end
• mail() do..end for
                        end
  multipart
More ActionMailer
class UserMailer < ActionMailer::Base

      default   :from => "admin@testapp.com"

      def welcome(user, subdomain)
        @user = user
        @subdomain = subdomain

        attachments['test.pdf']      = File.read("#   {Rails.root}/public/test.pdf")

        mail(:to => @user.email, :subject => "Welcome to TestApp") do |format|
         format.html    { render 'other_html_welcome' }
         format.text { render 'other_text_welcome' }
        end
      end

end
More ActionMailer
class UserMailer < ActionMailer::Base

      default   :from => "admin@testapp.com"

      def welcome(user, subdomain)
        @user = user
        @subdomain = subdomain

        attachments['test.pdf']      = File.read("#   {Rails.root}/public/test.pdf")

        mail(:to => @user.email, :subject => "Welcome to TestApp") do |format|
         format.html    { render 'other_html_welcome' }
         format.text { render 'other_text_welcome' }
        end
      end

end
Models
• New ActiveModel
                      MyClass
• Encapsulates         ActiveModel::Validations

  features
                           Serialization
                       ActiveModel::Observing

• ‘include’ in non-
                       ActiveModel::Serialization
  ActiveRecords
                               etc..
• also...
Find and Scopes
• Relational algebra   # Article.find(:all, :order => "published_at
                       desc", :limit => 10)
                       Article.order("published_at desc").limit(10)

• chained methods      # Article.find(:all, :conditions => ["title = ?",
                       ‘This’], :include => :comments)
                       Article.where("title = ?",

• named_scope now      ‘This’).includes(:comments)



  scope                # Article.find(:first, :order => "published_at
                       desc")
                       Article.order("published_at").last


• conditions now       # models/active_record.rb
                       scope :visible, where("hidden != ?", true)
  where                scope :published, lambda { where("published_at
                       <= ?", Time.zone.now) }
                       scope :recent, visible.published.order("published_at
                       desc")

• deferred retrieval
ActiveRelation Methods
                  •      where                          •    limit
                  •      select                         •    joins
                  •      order                          •    group
                  •      offset                         •    having
                  •      includes                       •    lock
                  •      readonly
                  •      from
Book.where(:author => "Austen").include(:versions).order(:title).limit(10)
Executed only when the data is needed
In Views
                                   <%= form_for @product do |f| %>
• ‘=’ required for all tags        <% end %>

  that output content              <%= div_for @product do %>
                                   <% end %>

  including blocks, like           <% @comments.each do |c| %>
                                   <% end %>
  ‘form_for’
                                   <% content_for :side do %>
                                   <% end %>

• ‘-’ no longer required           <% cache do %>
                                   <% end %>
  to suppress spaces
                              <!-- products/show.html.erb -->
                              <%= admin_area do %>
• write_output_buffer           <%= link_to "Edit", edit_product_path(@product) %> |
                                <%= link_to "Destroy", @product, :confirm => "Are you
                              sure?", :method => :delete %> |
  method in helpers             <%= link_to "View All", products_path %>
                              <% end %>

                              # application_helper.rb

• no ‘=’ for cache helper     def admin_area(&block)
                                content = with_output_buffer(&block)
                                content_tag(:div, content, :class => "admin")
                              end
XSS Protection
• ‘h’ assumed
                           <!-- views/comments/_comment.html.erb -->
                           <div class="comment">
• new ‘raw’ method to      %>
                             <%= strong link_to(comment.name, comment.url)


  unescape                    <p><%= comment.content %></p>
                           </div>

                           # rails c
• html_safe? and           "foo".html_safe?
                           safe = "safe".html_safe
                           safe.html_safe?
  html_safe method to
                           # application_helper.rb
  check/make string safe   def strong(content)
                             "<strong>#{h(content)}</strong>".html_safe
                           end

• ‘html_safe’ must be
  used on helper output
Unobtrusive Javascript
                           <!-- products/index.html.erb -->
                           <% form_tag products_path, :method => :get, :remote => true do
• Makes use of ‘data-      %>
                              <p>

  remote’ tag for Ajax forms    <%= text_field_tag :search, params[:search] %>
                                <%= submit_tag "Search", :name => nil %>
                              </p>
                           <% end %>

• Other Javascript tag     <a href="#" id="alert" data-message="Hello UJS!">Click Here</a>


  ‘data-’ attributes       <%= link_to 'Destroy', post, :method => :delete %>



  supported                       In rails.js
                                  document.observe("dom:loaded", function() {

                                    $(document.body).observe("click", function(event) {

• http://github.com/rails/              var message = event.element().readAttribute('data-confirm');
                                        if (message) {

  jquery-ujs                            }
                                          // ... Do a confirm box



                                        var element = event.findElement("a[data-remote=true]");
                                        if (element) {


• http://github.com/rails/
                                          // ... Do the AJAX call
                                        }

                                        var element = event.findElement("a[data-method]");

  prototype_legacy_helper               if (element) {
                                          // ... Create a form
                                        }

                                  });
The Commandline
  • rails s[erver] = start server

  • rails c = start console

  • rails g[enerate] = generate

  Some new rake commands:-

  • rake db:forward

  • rake routes CONTROLLER=users
Generators
• All rewritten: http://www.viget.com/extend/rails-3-
  generators-the-old-faithful

• More easily build new templates with Thor: http://
  caffeinedd.com/guides/331-making-generators-for-
  rails-3-with-thor

• RAILS_ROOT/lib/templates override generator
  templates

• Rails::Generators::TestCase for testing generators

• _form partials   and smart labels for form buttons
Extras

• config.filter_parameters << :password
• RAILS_ENV, RAILS_ROOT, etc.
• redirect_to(@user, :notice => ... )
• ‘validates :login, :presence =>
  true, :length => { :minimum =>
  4}, :inclusion => { :in => [1, 2, 3] }’
l18n

• I18n faster
• I18n on any object
• attributes have default translations
• Submit tags label automatically
• labels pass attribute name
Before Upgrading...
    Note: Currently Beta2, so need to be brave/sure/low-impact


You will need/want:-
• www.railsupgradehandbook.com Jeremy McAnally

• http://github.com/rails/rails_upgrade

• RVM or other multi-ruby support

• Good test coverage (without factory_girl/shoulda?)

• Rails 3 hosting

• New git branch?
RVM
• Run any version of Ruby in its own environment

• Rails 3 needs at least 1.8.7 - Serious bugs in 1.9.1,
  recommended version 1.9.2

• RVM lets you find best working one for you

• Installation instructions at:

  • http://gist.github.com/296055

  • http://railscasts.com/episodes/200-rails-3-beta-and-rvm

• no SUDO required
Update Check plugin
• http://github.com/rails/rails_upgrade

• Scan for changes to code, etc.

• Convert most routes automatically

• Create bundler Gemfile

• Back up important files

• Create starter configuration
The Rest of the Process
       www.railsupgradehandbook.com   Jeremy McAnally




 • Regenerate the app

 • Application.rb & environment.rb

 • Check and tidy up routes manually

 • Complete Gemfile manually

 • Make all tests run

 • Other Rails 3 enhancements (can be deferred)

 • Host prepare and deploy (Heroku?)
Help & thanks
•   http://www.railsupgradehandbook.com/ by Jeremy McAnally

•   http://railscasts.com by Ryan Bates

•   http://guides.rails.info/3_0_release_notes.html

•   http://www.railsplugins.org/

•   http://ruby5.envylabs.com/

•   http://blog.envylabs.com/2010/02/rails-3-beautiful-code/ by Greg
    Pollack

•   http://weblog.rubyonrails.org/2010/4/1/rails-3-0-second-beta-release

Contenu connexe

Tendances

RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3Anton Narusberg
 
Padrino - the Godfather of Sinatra
Padrino - the Godfather of SinatraPadrino - the Godfather of Sinatra
Padrino - the Godfather of SinatraStoyan Zhekov
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDBOpusVL
 
An introduction to Rails 3
An introduction to Rails 3An introduction to Rails 3
An introduction to Rails 3Blazing Cloud
 
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafDSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafTim Donohue
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappersManolis Vavalis
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursJ V
 
9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North Delhi9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North DelhiJessica Smith
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php coolpics
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedarya krazydude
 
/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repository/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repositoryJukka Zitting
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swaggerTony Tam
 

Tendances (20)

Apache Jackrabbit
Apache JackrabbitApache Jackrabbit
Apache Jackrabbit
 
RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3
 
Padrino - the Godfather of Sinatra
Padrino - the Godfather of SinatraPadrino - the Godfather of Sinatra
Padrino - the Godfather of Sinatra
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
 
An introduction to Rails 3
An introduction to Rails 3An introduction to Rails 3
An introduction to Rails 3
 
Web Ninja
Web NinjaWeb Ninja
Web Ninja
 
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + ThymeleafDSpace UI Prototype Challenge: Spring Boot + Thymeleaf
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
 
Java
JavaJava
Java
 
SOA on Rails
SOA on RailsSOA on Rails
SOA on Rails
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy Behaviours
 
Introduction to CQ5
Introduction to CQ5Introduction to CQ5
Introduction to CQ5
 
9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North Delhi9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North Delhi
 
Bhavesh ro r
Bhavesh ro rBhavesh ro r
Bhavesh ro r
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php
 
Intro to sbt-web
Intro to sbt-webIntro to sbt-web
Intro to sbt-web
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
 
/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repository/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repository
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
 

En vedette

OSOM - Building a community
OSOM - Building a communityOSOM - Building a community
OSOM - Building a communityMarcela Oniga
 
OSOM - Open source culture
OSOM - Open source cultureOSOM - Open source culture
OSOM - Open source cultureMarcela Oniga
 
Autonomics & Sympathetics
Autonomics & SympatheticsAutonomics & Sympathetics
Autonomics & SympatheticsMD Specialclass
 
Adrenergic receptor and mechanism of action by yehia matter
Adrenergic receptor and mechanism of action by yehia matter Adrenergic receptor and mechanism of action by yehia matter
Adrenergic receptor and mechanism of action by yehia matter yehiamatter
 
Adrenoceptor agonists
Adrenoceptor agonistsAdrenoceptor agonists
Adrenoceptor agonistswangye5056
 
Adrenergic blockers
Adrenergic blockersAdrenergic blockers
Adrenergic blockersraj kumar
 
G protein coupled receptors and their Signaling Mechanism
G protein coupled receptors and their Signaling MechanismG protein coupled receptors and their Signaling Mechanism
G protein coupled receptors and their Signaling MechanismFarazaJaved
 
Adrenergic antagonists alpha and beta blockers
Adrenergic antagonists   alpha and beta blockersAdrenergic antagonists   alpha and beta blockers
Adrenergic antagonists alpha and beta blockersZulcaif Ahmad
 
AUTONOMIC NERVOUS SYSTEM
AUTONOMIC NERVOUS SYSTEMAUTONOMIC NERVOUS SYSTEM
AUTONOMIC NERVOUS SYSTEMDr Nilesh Kate
 
Drugs acting on PNS
Drugs acting on PNSDrugs acting on PNS
Drugs acting on PNSmadan sigdel
 
Autonomic nervous system (1)
Autonomic nervous system (1)Autonomic nervous system (1)
Autonomic nervous system (1)Zulcaif Ahmad
 
Adrenergic agonists & antagonists
Adrenergic agonists & antagonistsAdrenergic agonists & antagonists
Adrenergic agonists & antagonistsBrian Piper
 
autonomic nervous system Ppt
autonomic nervous system Pptautonomic nervous system Ppt
autonomic nervous system Pptdrbskamble
 

En vedette (20)

OSOM - Building a community
OSOM - Building a communityOSOM - Building a community
OSOM - Building a community
 
OSOM - Open source culture
OSOM - Open source cultureOSOM - Open source culture
OSOM - Open source culture
 
Tutorial
TutorialTutorial
Tutorial
 
Autonomics & Sympathetics
Autonomics & SympatheticsAutonomics & Sympathetics
Autonomics & Sympathetics
 
Adrenergic receptor and mechanism of action by yehia matter
Adrenergic receptor and mechanism of action by yehia matter Adrenergic receptor and mechanism of action by yehia matter
Adrenergic receptor and mechanism of action by yehia matter
 
Adrenoceptor agonists
Adrenoceptor agonistsAdrenoceptor agonists
Adrenoceptor agonists
 
Alpha adrenergic blockers
Alpha adrenergic blockersAlpha adrenergic blockers
Alpha adrenergic blockers
 
Adrenergic blockers
Adrenergic blockersAdrenergic blockers
Adrenergic blockers
 
G protein coupled receptors and their Signaling Mechanism
G protein coupled receptors and their Signaling MechanismG protein coupled receptors and their Signaling Mechanism
G protein coupled receptors and their Signaling Mechanism
 
ADRENERGIC BLOCKERS
ADRENERGIC BLOCKERSADRENERGIC BLOCKERS
ADRENERGIC BLOCKERS
 
Beta blockers
Beta blockers Beta blockers
Beta blockers
 
Adrenergic antagonists alpha and beta blockers
Adrenergic antagonists   alpha and beta blockersAdrenergic antagonists   alpha and beta blockers
Adrenergic antagonists alpha and beta blockers
 
AUTONOMIC NERVOUS SYSTEM
AUTONOMIC NERVOUS SYSTEMAUTONOMIC NERVOUS SYSTEM
AUTONOMIC NERVOUS SYSTEM
 
Beta blockers
Beta blockers Beta blockers
Beta blockers
 
Autonomic Nervous System
Autonomic Nervous SystemAutonomic Nervous System
Autonomic Nervous System
 
Drugs acting on PNS
Drugs acting on PNSDrugs acting on PNS
Drugs acting on PNS
 
Autonomic nervous system (1)
Autonomic nervous system (1)Autonomic nervous system (1)
Autonomic nervous system (1)
 
Adrenergic agonists & antagonists
Adrenergic agonists & antagonistsAdrenergic agonists & antagonists
Adrenergic agonists & antagonists
 
Receptors
ReceptorsReceptors
Receptors
 
autonomic nervous system Ppt
autonomic nervous system Pptautonomic nervous system Ppt
autonomic nervous system Ppt
 

Similaire à Rails 3 (beta) Roundup

Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - IntroductionVagmi Mudumbai
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentNicolas Ledez
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaVasil Remeniuk
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature OptimizationsMaude Lemaire
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009Jason Davies
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Henry S
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationSociable
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase RubySergey Avseyev
 
CUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension PointsCUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension PointsAlfresco Software
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...Timofey Turenko
 

Similaire à Rails 3 (beta) Roundup (20)

Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Configuration management with Chef
Configuration management with ChefConfiguration management with Chef
Configuration management with Chef
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Rails3 changesets
Rails3 changesetsRails3 changesets
Rails3 changesets
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature Optimizations
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentation
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase Ruby
 
CUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension PointsCUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension Points
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
 

Dernier

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Rails 3 (beta) Roundup

  • 1. Rails 3 (beta) Roundup April 6, 2010
  • 2. Why Upgrade • Performance tighter & faster codebase, relational optimizations, shorter path to response, better scaling, better use of Rack & Middleware • Security better routing DSL, XSS protection, more powerful controller stack, better use of Rack & Middleware, fixes • Labour-savings easier routing, reliable gem management, easier Ajax, better code reuse, less monkey-patching, better & easier generators • Modernization Rack reliance, later Ruby, plug in new frameworks and components, new standards • Cost saving lower hardware requirements, less Gem maintenance, consistency means easier for developers
  • 3. HTTP://GUIDES.RAILS.INFO/3_0_RELEASE_NOTES.HTML Significant Features • Dependency management with Bundler • More concise router • Chainable database query language • New ActionMailer API • Unobtrusive JavaScript • Better modularity • Improved XSS protection
  • 4. Bundler http://railscasts.com/episodes/201-bundler get used to version juggling for now gem "rails", "3.0.0.beta" • all gems listed in # gem "rails", :git => "git://github.com/rails/ Gemfile rails.git" gem "sqlite3-ruby", :require => "sqlite3" • ‘setup’ gemfile # gem "rspec", :group => :test group :test do gem "webrat" end • ‘install’ gem install bundler bundle setup • ‘pack’ bundle install bundle unlock mate Gemfile bundle install --without=test • deploy app bundle pack # application.rb • unlock to modify require 'rails/all' Bundler.require(:default, Rails.env) if defined?(Bundler) Need version 9+. No config.gem required for Rails 3, although some need it for Rails 2.
  • 5. New Modular Architecture • “Railties framework is now a set of individual Railties, each inheriting from a new class, Rails::Railtie” • Third-party plugins hook into early stages of initialization • Rake tasks and generators part of the frameworks • “In short, Rails frameworks are now plugins to Rails” Action Mailer * Action Pack * Active Record * Active Resource * Active Model * Active Support • And features like ActiveRecord validations and serialization reusable, eg: include ActiveModel::Validations
  • 6. Routing resources :products do   • more concise get :detailed, :on => :member  end   block resources :forums do   DSL collection do   get :sortable   put :sort  end   resources :topics • rack routes end match "/secret" => "info#about", :constraints => { :user_agent => /Firefox/ } constraints :host => /localhost/ do   • constraints match "/secret" => "info#about"   match "/topsecret" => "info#about"   end  match "/hello" => proc { |env| [200, {}, "Hello Rack!"] } • other features root :to => "home#index" match "/about" => "info#about",  :as => :about
  • 7. Controllers • taller stack abstracting rendering, layouts, rack, AbstractController::Base etc ActionController::Metal • enhance by subclassing New relevant layer ActionController::Base Old • middleware layer ApplicationController • ‘respond_with(@post)’ MyController • flash[:notice] & flash[:alert]
  • 8. ActionMailer • like a controller r g mailer UserMailer welcome gives... • email types like actions class UserMailer < ActionMailer::Base def welcome(user, subdomain) @user = user • mail() to send @subdomain = subdomain mail(:from => "admin@testapp.com", :to => @user.email, • no ‘deliver_’ prefix :subject => "Welcome to TestApp") end • mail() do..end for end multipart
  • 9. More ActionMailer class UserMailer < ActionMailer::Base default :from => "admin@testapp.com" def welcome(user, subdomain) @user = user @subdomain = subdomain attachments['test.pdf'] = File.read("# {Rails.root}/public/test.pdf") mail(:to => @user.email, :subject => "Welcome to TestApp") do |format| format.html { render 'other_html_welcome' } format.text { render 'other_text_welcome' } end end end
  • 10. More ActionMailer class UserMailer < ActionMailer::Base default :from => "admin@testapp.com" def welcome(user, subdomain) @user = user @subdomain = subdomain attachments['test.pdf'] = File.read("# {Rails.root}/public/test.pdf") mail(:to => @user.email, :subject => "Welcome to TestApp") do |format| format.html { render 'other_html_welcome' } format.text { render 'other_text_welcome' } end end end
  • 11. Models • New ActiveModel MyClass • Encapsulates ActiveModel::Validations features Serialization ActiveModel::Observing • ‘include’ in non- ActiveModel::Serialization ActiveRecords etc.. • also...
  • 12. Find and Scopes • Relational algebra # Article.find(:all, :order => "published_at desc", :limit => 10) Article.order("published_at desc").limit(10) • chained methods # Article.find(:all, :conditions => ["title = ?", ‘This’], :include => :comments) Article.where("title = ?", • named_scope now ‘This’).includes(:comments) scope # Article.find(:first, :order => "published_at desc") Article.order("published_at").last • conditions now # models/active_record.rb scope :visible, where("hidden != ?", true) where scope :published, lambda { where("published_at <= ?", Time.zone.now) } scope :recent, visible.published.order("published_at desc") • deferred retrieval
  • 13. ActiveRelation Methods • where • limit • select • joins • order • group • offset • having • includes • lock • readonly • from Book.where(:author => "Austen").include(:versions).order(:title).limit(10) Executed only when the data is needed
  • 14. In Views <%= form_for @product do |f| %> • ‘=’ required for all tags <% end %> that output content <%= div_for @product do %> <% end %> including blocks, like <% @comments.each do |c| %> <% end %> ‘form_for’ <% content_for :side do %> <% end %> • ‘-’ no longer required <% cache do %> <% end %> to suppress spaces <!-- products/show.html.erb --> <%= admin_area do %> • write_output_buffer <%= link_to "Edit", edit_product_path(@product) %> | <%= link_to "Destroy", @product, :confirm => "Are you sure?", :method => :delete %> | method in helpers <%= link_to "View All", products_path %> <% end %> # application_helper.rb • no ‘=’ for cache helper def admin_area(&block) content = with_output_buffer(&block) content_tag(:div, content, :class => "admin") end
  • 15. XSS Protection • ‘h’ assumed <!-- views/comments/_comment.html.erb --> <div class="comment"> • new ‘raw’ method to %> <%= strong link_to(comment.name, comment.url) unescape <p><%= comment.content %></p> </div> # rails c • html_safe? and "foo".html_safe? safe = "safe".html_safe safe.html_safe? html_safe method to # application_helper.rb check/make string safe def strong(content) "<strong>#{h(content)}</strong>".html_safe end • ‘html_safe’ must be used on helper output
  • 16. Unobtrusive Javascript <!-- products/index.html.erb --> <% form_tag products_path, :method => :get, :remote => true do • Makes use of ‘data- %> <p> remote’ tag for Ajax forms <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %> • Other Javascript tag <a href="#" id="alert" data-message="Hello UJS!">Click Here</a> ‘data-’ attributes <%= link_to 'Destroy', post, :method => :delete %> supported In rails.js document.observe("dom:loaded", function() { $(document.body).observe("click", function(event) { • http://github.com/rails/ var message = event.element().readAttribute('data-confirm'); if (message) { jquery-ujs } // ... Do a confirm box var element = event.findElement("a[data-remote=true]"); if (element) { • http://github.com/rails/ // ... Do the AJAX call } var element = event.findElement("a[data-method]"); prototype_legacy_helper if (element) { // ... Create a form } });
  • 17. The Commandline • rails s[erver] = start server • rails c = start console • rails g[enerate] = generate Some new rake commands:- • rake db:forward • rake routes CONTROLLER=users
  • 18. Generators • All rewritten: http://www.viget.com/extend/rails-3- generators-the-old-faithful • More easily build new templates with Thor: http:// caffeinedd.com/guides/331-making-generators-for- rails-3-with-thor • RAILS_ROOT/lib/templates override generator templates • Rails::Generators::TestCase for testing generators • _form partials and smart labels for form buttons
  • 19. Extras • config.filter_parameters << :password • RAILS_ENV, RAILS_ROOT, etc. • redirect_to(@user, :notice => ... ) • ‘validates :login, :presence => true, :length => { :minimum => 4}, :inclusion => { :in => [1, 2, 3] }’
  • 20. l18n • I18n faster • I18n on any object • attributes have default translations • Submit tags label automatically • labels pass attribute name
  • 21. Before Upgrading... Note: Currently Beta2, so need to be brave/sure/low-impact You will need/want:- • www.railsupgradehandbook.com Jeremy McAnally • http://github.com/rails/rails_upgrade • RVM or other multi-ruby support • Good test coverage (without factory_girl/shoulda?) • Rails 3 hosting • New git branch?
  • 22. RVM • Run any version of Ruby in its own environment • Rails 3 needs at least 1.8.7 - Serious bugs in 1.9.1, recommended version 1.9.2 • RVM lets you find best working one for you • Installation instructions at: • http://gist.github.com/296055 • http://railscasts.com/episodes/200-rails-3-beta-and-rvm • no SUDO required
  • 23. Update Check plugin • http://github.com/rails/rails_upgrade • Scan for changes to code, etc. • Convert most routes automatically • Create bundler Gemfile • Back up important files • Create starter configuration
  • 24. The Rest of the Process www.railsupgradehandbook.com Jeremy McAnally • Regenerate the app • Application.rb & environment.rb • Check and tidy up routes manually • Complete Gemfile manually • Make all tests run • Other Rails 3 enhancements (can be deferred) • Host prepare and deploy (Heroku?)
  • 25. Help & thanks • http://www.railsupgradehandbook.com/ by Jeremy McAnally • http://railscasts.com by Ryan Bates • http://guides.rails.info/3_0_release_notes.html • http://www.railsplugins.org/ • http://ruby5.envylabs.com/ • http://blog.envylabs.com/2010/02/rails-3-beautiful-code/ by Greg Pollack • http://weblog.rubyonrails.org/2010/4/1/rails-3-0-second-beta-release

Notes de l'éditeur