SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Rails 2.3


 Brian Turnbull
http://brianturnbull.com
Templates
rails app
                           rails app’
template


        rails app -m template.rb

rails app -m http://example.com/template

rake rails:template LOCATION=template.rb
Templates
# template.rb
gem quot;hpricotquot;
rake quot;gems:installquot;
run quot;rm public/index.htmlquot;
generate :scaffold, quot;person name:stringquot;
route quot;map.root :controller => 'people'quot;
rake quot;db:migratequot;

git :init
git :add => quot;.quot;
git :commit => quot;-a -m 'Initial commit'quot;


      Pratik Naik — http://m.onkey.org/2008/12/4/rails-templates
Templates

      Jeremy McAnally’s Template Library
http://github.com/jeremymcanally/rails-templates/tree/master
Engines
                Rails Plugins turned to Eleven

                Share Models, Views, and
                Controllers with Host App

                Share Routes with Host App


http://rails-engines.org/news/2009/02/02/engines-in-rails-2-3/
Engines

                Not Yet Fully Baked

                Manually Manage Migrations

                Manually Merge Public Assets



http://rails-engines.org/news/2009/02/02/engines-in-rails-2-3/
Nested Transactions
User.transaction do
  User.create(:username => 'Admin')
  User.transaction(:requires_new => true) do
    User.create(:username => 'Regular')
    raise ActiveRecord::Rollback
  end
end

User.find(:all)     # => Returns only Admin




        http://guides.rubyonrails.org/2_3_release_notes.html
Nested Attributes

class Book < ActiveRecord::Base
  has_one :author
  has_many :pages

  accepts_nested_attributes_for :author, :pages
end




        http://guides.rubyonrails.org/2_3_release_notes.html
Nested Forms
class Book < ActiveRecord::Base
  has_many :authors
  accepts_nested_attributes_for :authors
end

<% form_for @book do |book_form| %>
  <div>
    <%= book_form.label :title, 'Book Title:' %>
    <%= book_form.text_field :title %>
  </div>
  <% book_form.fields_for :authors do |author_form| %>
      <div>
        <%= author_form.label :name, 'Author Name:' %>
        <%= author_form.text_field :name %>
      </div>
    <% end %>
  <% end %>
  <%= book_form.submit %>
<% end %>


            http://guides.rubyonrails.org/2_3_release_notes.html
Dynamic and Default Scopes
## id          Integer
## customer_id Integer
## status      String
## entered_at DateTime
class Order < ActiveRecord::Base
  belongs_to :customer
  default_scope :order => 'entered_at'
end

Order.scoped_by_customer_id(12)
Order.scoped_by_customer_id(12).find(:all,
  :conditions => quot;status = 'open'quot;)
Order.scoped_by_customer_id(12).scoped_by_status(quot;openquot;)




          http://guides.rubyonrails.org/2_3_release_notes.html
Other Changes

          Multiple Conditions for Callbacks
          HTTP Digest Authentication
          Lazy Loaded Sessions
          Localized Views
          and More!



http://guides.rubyonrails.org/2_3_release_notes.html
Rails 2.3
Rails Metal
SPEED
Simplicity
Metal Endpoint
 ## app/metal/hello_metal.rb
 class HelloMetal
   def self.call(env)
     if env[quot;PATH_INFOquot;] =~ /^/hello/metal/
       [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hello, Metal!quot;]]
     else
       [404, {quot;Content-Typequot; => quot;text/htmlquot;}, [quot;Not Foundquot;]]
     end
   end
 end




http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m
Equivalent Controller

 ## app/controllers/hello_rails_controller.rb
 class HelloRailsController < ApplicationController
   def show
     headers['Content-Type'] = 'text/plain'
     render :text => 'Hello, Rails!'
   end
 end




http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m
Sinatra!
 require 'sinatra'
 Sinatra::Application.set(:run => false)
 Sinatra::Application.set(:environment => :production)

 HelloSinatra = Sinatra::Application.new unless defined? HelloSinatra

 get '/hello/sinatra' do
   response['Content-Type'] = 'text/plain'
   'Hello, Sinatra!'
 end




http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m
Rack
Object.call(env)


[status,
 headers,
 response]
Metal Endpoint
## app/metal/hello_metal.rb
class HelloMetal
  def self.call(env)
    if env[quot;PATH_INFOquot;] =~ /^/hello/metal/
      [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hello, Metal!quot;]]
    else
      [404, {quot;Content-Typequot; => quot;text/htmlquot;}, [quot;Not Foundquot;]]
    end
  end
end
Rack Middleware in Rails
            Rails Dispatcher
call(env)                      [s,h,r]

              Middleware
call(env)                      [s,h,r]

              Middleware
call(env)                      [s,h,r]

              Web Server
Rack Middleware in Rails
% rake middleware
use Rack::Lock
use ActionController::Failsafe
use ActionController::Session::CookieStore
use Rails::Rack::Metal
use ActionController::RewindableInput
use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActiveRecord::QueryCache
run ActionController::Dispatcher.new
Rack Middleware in Rails
% rake middleware
use Rack::Lock
use ActionController::Failsafe
use ActionController::Session::CookieStore
use Rails::Rack::Metal
use ActionController::RewindableInput
use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActiveRecord::QueryCache
run ActionController::Dispatcher.new
Django > Rails?
## lib/middleware/django_middleware.rb
class DjangoMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, response = @app.call(env)
    new_response = []
    response.each do |part|
      new_response << part.gsub(/Rails/, 'Django')
    end
    [status, headers, new_response]
  end
end

## config/environment.rb
config.middleware.use DjangoMiddleware
http://github.com/bturnbull/bturnbull-metal-demo

Weitere ähnliche Inhalte

Was ist angesagt?

Curing Webpack Cancer
Curing Webpack CancerCuring Webpack Cancer
Curing Webpack CancerNeel Shah
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3Rory Gianni
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6Rory Gianni
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6Rory Gianni
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful RailsBen Scofield
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2A.K.M. Ahsrafuzzaman
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Ajax pagination using j query in rails3
Ajax pagination using j query in rails3Ajax pagination using j query in rails3
Ajax pagination using j query in rails3Andolasoft Inc
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routingBrajesh Yadav
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life CycleAbhishek Sur
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Vikas Chauhan
 
Merb Pluming - The Router
Merb Pluming - The RouterMerb Pluming - The Router
Merb Pluming - The Routercarllerche
 

Was ist angesagt? (20)

Curing Webpack Cancer
Curing Webpack CancerCuring Webpack Cancer
Curing Webpack Cancer
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
Rails::Engine
Rails::EngineRails::Engine
Rails::Engine
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Ajax pagination using j query in rails3
Ajax pagination using j query in rails3Ajax pagination using j query in rails3
Ajax pagination using j query in rails3
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
multiple views and routing
multiple views and routingmultiple views and routing
multiple views and routing
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Rack
RackRack
Rack
 
Merb Pluming - The Router
Merb Pluming - The RouterMerb Pluming - The Router
Merb Pluming - The Router
 

Andere mochten auch (6)

Peer Advising Wiki Tutorial
Peer Advising Wiki TutorialPeer Advising Wiki Tutorial
Peer Advising Wiki Tutorial
 
Monit - NHRuby May 2009
Monit - NHRuby May 2009Monit - NHRuby May 2009
Monit - NHRuby May 2009
 
Go Ahead, Get Close; Commit to Customer Relationships through Direct Response
Go Ahead, Get Close; Commit to Customer Relationships through Direct ResponseGo Ahead, Get Close; Commit to Customer Relationships through Direct Response
Go Ahead, Get Close; Commit to Customer Relationships through Direct Response
 
Four Bear Advisors Presentation, Spring 2012
Four Bear Advisors Presentation, Spring 2012Four Bear Advisors Presentation, Spring 2012
Four Bear Advisors Presentation, Spring 2012
 
RVM - NHRuby Nov 2009
RVM - NHRuby Nov 2009RVM - NHRuby Nov 2009
RVM - NHRuby Nov 2009
 
OOP Intro in Ruby for NHRuby Feb 2010
OOP Intro in Ruby for NHRuby Feb 2010OOP Intro in Ruby for NHRuby Feb 2010
OOP Intro in Ruby for NHRuby Feb 2010
 

Ähnlich wie Rails 2.3 and Rack - NHRuby Feb 2009

Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amfrailsconf
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialYi-Ting Cheng
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon RailsPaul Pajo
 
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編Masakuni Kato
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous MerbMatt Todd
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On RailsWen-Tien Chang
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
WebcampZG - Rails 4
WebcampZG - Rails 4WebcampZG - Rails 4
WebcampZG - Rails 4shnikola
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsJohn Brunswick
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On RailsSteve Keener
 
Introduction To ASP.NET MVC
Introduction To ASP.NET MVCIntroduction To ASP.NET MVC
Introduction To ASP.NET MVCAlan Dean
 

Ähnlich wie Rails 2.3 and Rack - NHRuby Feb 2009 (20)

Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
Rails 3
Rails 3Rails 3
Rails 3
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Jicc teaching rails
Jicc teaching railsJicc teaching rails
Jicc teaching rails
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon Rails
 
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Merb Router
Merb RouterMerb Router
Merb Router
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
WebcampZG - Rails 4
WebcampZG - Rails 4WebcampZG - Rails 4
WebcampZG - Rails 4
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Rack
RackRack
Rack
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Introduction To ASP.NET MVC
Introduction To ASP.NET MVCIntroduction To ASP.NET MVC
Introduction To ASP.NET MVC
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 

Kürzlich hochgeladen

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
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 FMESafe Software
 
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
 
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 FresherRemote DBA Services
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
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 DiscoveryTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
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
 
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
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Rails 2.3 and Rack - NHRuby Feb 2009

  • 1. Rails 2.3 Brian Turnbull http://brianturnbull.com
  • 2. Templates rails app rails app’ template rails app -m template.rb rails app -m http://example.com/template rake rails:template LOCATION=template.rb
  • 3. Templates # template.rb gem quot;hpricotquot; rake quot;gems:installquot; run quot;rm public/index.htmlquot; generate :scaffold, quot;person name:stringquot; route quot;map.root :controller => 'people'quot; rake quot;db:migratequot; git :init git :add => quot;.quot; git :commit => quot;-a -m 'Initial commit'quot; Pratik Naik — http://m.onkey.org/2008/12/4/rails-templates
  • 4. Templates Jeremy McAnally’s Template Library http://github.com/jeremymcanally/rails-templates/tree/master
  • 5. Engines Rails Plugins turned to Eleven Share Models, Views, and Controllers with Host App Share Routes with Host App http://rails-engines.org/news/2009/02/02/engines-in-rails-2-3/
  • 6. Engines Not Yet Fully Baked Manually Manage Migrations Manually Merge Public Assets http://rails-engines.org/news/2009/02/02/engines-in-rails-2-3/
  • 7. Nested Transactions User.transaction do User.create(:username => 'Admin') User.transaction(:requires_new => true) do User.create(:username => 'Regular') raise ActiveRecord::Rollback end end User.find(:all) # => Returns only Admin http://guides.rubyonrails.org/2_3_release_notes.html
  • 8. Nested Attributes class Book < ActiveRecord::Base has_one :author has_many :pages accepts_nested_attributes_for :author, :pages end http://guides.rubyonrails.org/2_3_release_notes.html
  • 9. Nested Forms class Book < ActiveRecord::Base has_many :authors accepts_nested_attributes_for :authors end <% form_for @book do |book_form| %> <div> <%= book_form.label :title, 'Book Title:' %> <%= book_form.text_field :title %> </div> <% book_form.fields_for :authors do |author_form| %> <div> <%= author_form.label :name, 'Author Name:' %> <%= author_form.text_field :name %> </div> <% end %> <% end %> <%= book_form.submit %> <% end %> http://guides.rubyonrails.org/2_3_release_notes.html
  • 10. Dynamic and Default Scopes ## id Integer ## customer_id Integer ## status String ## entered_at DateTime class Order < ActiveRecord::Base belongs_to :customer default_scope :order => 'entered_at' end Order.scoped_by_customer_id(12) Order.scoped_by_customer_id(12).find(:all, :conditions => quot;status = 'open'quot;) Order.scoped_by_customer_id(12).scoped_by_status(quot;openquot;) http://guides.rubyonrails.org/2_3_release_notes.html
  • 11. Other Changes Multiple Conditions for Callbacks HTTP Digest Authentication Lazy Loaded Sessions Localized Views and More! http://guides.rubyonrails.org/2_3_release_notes.html
  • 15. Metal Endpoint ## app/metal/hello_metal.rb class HelloMetal def self.call(env) if env[quot;PATH_INFOquot;] =~ /^/hello/metal/ [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hello, Metal!quot;]] else [404, {quot;Content-Typequot; => quot;text/htmlquot;}, [quot;Not Foundquot;]] end end end http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m
  • 16. Equivalent Controller ## app/controllers/hello_rails_controller.rb class HelloRailsController < ApplicationController def show headers['Content-Type'] = 'text/plain' render :text => 'Hello, Rails!' end end http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m
  • 17. Sinatra! require 'sinatra' Sinatra::Application.set(:run => false) Sinatra::Application.set(:environment => :production) HelloSinatra = Sinatra::Application.new unless defined? HelloSinatra get '/hello/sinatra' do response['Content-Type'] = 'text/plain' 'Hello, Sinatra!' end http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m
  • 19. Metal Endpoint ## app/metal/hello_metal.rb class HelloMetal def self.call(env) if env[quot;PATH_INFOquot;] =~ /^/hello/metal/ [200, {quot;Content-Typequot; => quot;text/plainquot;}, [quot;Hello, Metal!quot;]] else [404, {quot;Content-Typequot; => quot;text/htmlquot;}, [quot;Not Foundquot;]] end end end
  • 20. Rack Middleware in Rails Rails Dispatcher call(env) [s,h,r] Middleware call(env) [s,h,r] Middleware call(env) [s,h,r] Web Server
  • 21. Rack Middleware in Rails % rake middleware use Rack::Lock use ActionController::Failsafe use ActionController::Session::CookieStore use Rails::Rack::Metal use ActionController::RewindableInput use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::QueryCache run ActionController::Dispatcher.new
  • 22. Rack Middleware in Rails % rake middleware use Rack::Lock use ActionController::Failsafe use ActionController::Session::CookieStore use Rails::Rack::Metal use ActionController::RewindableInput use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::QueryCache run ActionController::Dispatcher.new
  • 23. Django > Rails? ## lib/middleware/django_middleware.rb class DjangoMiddleware def initialize(app) @app = app end def call(env) status, headers, response = @app.call(env) new_response = [] response.each do |part| new_response << part.gsub(/Rails/, 'Django') end [status, headers, new_response] end end ## config/environment.rb config.middleware.use DjangoMiddleware