SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3
Anton Narusberg
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
Manolis Vavalis
 

Was ist angesagt? (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
 

Andere mochten auch

Adrenoceptor agonists
Adrenoceptor agonistsAdrenoceptor agonists
Adrenoceptor agonists
wangye5056
 
Adrenergic blockers
Adrenergic blockersAdrenergic blockers
Adrenergic blockers
raj kumar
 
Adrenergic antagonists alpha and beta blockers
Adrenergic antagonists   alpha and beta blockersAdrenergic antagonists   alpha and beta blockers
Adrenergic antagonists alpha and beta blockers
Zulcaif Ahmad
 
Autonomic nervous system (1)
Autonomic nervous system (1)Autonomic nervous system (1)
Autonomic nervous system (1)
Zulcaif Ahmad
 

Andere mochten auch (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
 

Ähnlich wie 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 Finish
Yehuda Katz
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
Vasil Remeniuk
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase Ruby
Sergey Avseyev
 

Ähnlich wie 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...
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

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

Hinweis der Redaktion