SlideShare a Scribd company logo
1 of 60
Download to read offline
What’s new in Rails 2.1?
           Keith Pitty

       Sydney Rails Meetup
          11 June 2008
over 1,400 contributors
more than 1,600 patches
Major features
 • Time zones
 • Dirty tracking
 • Gem dependencies
 • Named scope
 • UTC-based migrations
 • Better caching
New!




Time zones
courtesy of Geoff Busing
$ rake -T time
(in /Users/keithpitty/work/rails2.1demo)
rake time:zones:all    # Displays names of all time zones recognized by the...
rake time:zones:local # Displays names of time zones recognized by the Rai...
rake time:zones:us     # Displays names of US time zones recognized by the ...
$ rake time:zones:local

* UTC +10:00 *
Brisbane
Canberra
Guam
Hobart
Melbourne
Port Moresby
Sydney
Vladivostok
# config/environment.rb
config.time_zone = 'Sydney'
Times now stored in UTC in the db
but displayed using the default time zone
Warning!



If upgrading, times will need to be converted to UTC
Example



Add time zone support to users
Add time_zone to User model
Add time_zone_select to signup view
<h1>Sign up as a new user</h1>
<% @user.password = @user.password_confirmation = nil %>

<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| -%>
<p><label for=quot;loginquot;>Login</label><br/>
<%= f.text_field :login %></p>

<p><label for=quot;emailquot;>Email</label><br/>
<%= f.text_field :email %></p>

<p><label for=quot;passwordquot;>Password</label><br/>
<%= f.password_field :password %></p>

<p><label for=quot;password_confirmationquot;>Confirm Password</
label><br/>
<%= f.password_field :password_confirmation %></p>

<p><label for=quot;time_zonequot;>Time zone</label><br/>
<%= f.time_zone_select :time_zone, TimeZone.all %>

<p><%= submit_tag 'Sign up' %></p>
<% end -%>
Use before_filter to set time zone
   in ApplicationController
class ApplicationController < ActionController::Base
  helper :all
  protect_from_forgery

  include AuthenticatedSystem

 before_filter :set_user_time_zone

  private

  def set_user_time_zone
    Time.zone = current_user.time_zone if logged_in?
  end

end
New!




Dirty tracking
$ ./script/console
Loading development environment (Rails 2.1.0)
>> Beer.find :first
=> #<Beer id: 1, name: quot;Coopers Sparkling Alequot;, created_at: quot;2008-06-05 11:31:55quot;,
updated_at: quot;2008-06-05 11:31:55quot;>
>> b.changed?
=> false
>> b.name = quot;Coopers Pale Alequot;
=> quot;Coopers Pale Alequot;
>> b.changed?
=> true
>> b.changed
=> [quot;namequot;]
>> b.name_changed?
=> true
>> b.name_was
=> quot;Coopers Sparkling Alequot;
>> b.changes
=> {quot;namequot;=>[quot;Coopers Sparkling Alequot;, quot;Coopers Pale Alequot;]}
>> b.save
=> true
>> b.changed?
=> false
Partial updates by default in new Rails 2.1 apps
SQL (0.000138)   BEGIN
  Beer Update (0.000304)   UPDATE `beers` SET `updated_at` =
'2008-06-05 11:38:01', `name` = 'Coopers Pale Ale' WHERE
`id` = 1
  SQL (0.005019)   COMMIT
Warning!




Updates via other than attr= writer
>>   b.name_will_change!
=>   quot;Coopers Pale Alequot;
>>   b.name.upcase!
=>   quot;COOPERS PALE ALEquot;
>>   b.name_change
=>   [quot;Coopers Pale Alequot;, quot;COOPERS PALE ALEquot;]
New!




Gem Dependencies
$ rake -T gem
(in /Users/keithpitty/work/rails2.1demo)
rake gems                      # List the gems that this rails application ...
rake gems:build                # Build any native extensions for unpacked gems
rake gems:install              # Installs all required gems for this applic...
rake gems:unpack               # Unpacks the specified gem into vendor/gems.
rake gems:unpack:dependencies # Unpacks the specified gems and its depende...
rake rails:freeze:gems         # Lock this application to the current gems ...
# environment.rb

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  config.time_zone = 'Sydney'
  config.action_controller.session = {
    :session_key => '_rails2.1demo_session',
    :secret      =>
'f4a5c1596f8fff01033b7417629c47fb6344748864b8f3a25fc6884b1ea41d214642f8eba01aa274ef9d128
1fc6cdc23bc33ea57ac66878a7b1164b96d875343'
  }

  config.gem quot;hpricotquot;, :version => '0.6', :source => quot;http://code.whytheluckystiff.netquot;
  config.gem quot;aws-s3quot;, :lib => quot;aws/s3quot;
end
$ rake gems
(in /Users/keithpitty/work/rails2.1demo)
[I] hpricot = 0.6
[ ] aws-s3

I = Installed
F = Frozen
$ rake gems:install
$ rake gems:unpack
$ rake gems:unpack GEM=hpricot
$ rake gems:unpack:dependencies
$ rake gems:build
# test.rb
config.gem quot;mochaquot;
$ rake gems RAILS_ENV='test'
(in /Users/keithpitty/work/rails2.1demo)
[I] hpricot = 0.6
[ ] aws-s3
[ ] mocha

I = Installed
F = Frozen
New!




Named scope
courtesy of Nick Kallen
class Beer < ActiveRecord::Base
  named_scope :available, :conditions => {:available => true}
  named_scope :unavailable, :conditions => {:available => false}
  named_scope :heavy, :conditions => {:full_strength => true}
  named_scope :light, :conditions => {:full_strength => false}
  named_scope :cats_piss, :conditions => {:rating => 0..3}
  named_scope :drinkable, :conditions => ['rating > 3']
  named_scope :minimum_rating,
                lambda { |min_rating| { :conditions =>
                                          ['rating >= ?', min_rating] } }
  named_scope :rated,
                lambda { |rating| { :conditions =>
                                      ['rating = ?', rating] } }
  named_scope :awesome,
                lambda { |*args| { :conditions =>
                                     ['rating >= ?', (args.first || 9)] } }
end
>>   Beer.count
=>   15
>>   Beer.available.count
=>   9
>>   Beer.heavy.available.count
=>   8
>>   Beer.heavy.available.drinkable.count
=>   6
>>   Beer.heavy.available.minimum_rating(7).count
=>   5
>>   Beer.heavy.available.awesome.count
=>   3
>>   Beer.heavy.available.awesome(10).count
=>   1
>> Beer.heavy.available.awesome(10)
=> [#<Beer id: 888319404, name: quot;Coopers Sparkling Alequot;,
brewer: quot;Coopersquot;, rating: 10, available: true,
full_strength: true, created_at: quot;2008-06-08 07:13:17quot;,
updated_at: quot;2008-06-08 07:13:17quot;>]
>> Beer.rated(0)
=> [#<Beer id: 177722761, name: quot;Fosters Lagerquot;,
brewer: quot;Fostersquot;, rating: 0, available: false,
full_strength: true, created_at: quot;2008-06-08
07:13:17quot;, updated_at: quot;2008-06-08 07:13:17quot;>]
Also: named scope extensions, anonymous scopes
New!




UTC-based migrations
Migration prefix no longer simply sequential
Migration prefix now uses UTC timestamp
mysql> select * from schema_migrations;
+----------------+
| version        |
+----------------+
| 20080604194357 |
| 20080604195453 |
| 20080605112923 |
+----------------+
3 rows in set (0.00 sec)
Especially helpful for teams (avoids most conflicts)
Also helpful when working on branches
Migrations are applied intelligently
Also: change_table method introduced to migrations
New!




Better caching
Specify preferred caching engine in environment.rb
# Following options supplied in Rails 2.1:
ActionController::Base.cache_store = memory_store
ActionController::Base.cache_store = file_store, quot;path/to/cache/directoryquot;
ActionController::Base.cache_store = drb_store, quot;druby://localhost:9192quot;
ActionController::Base.cache_store = mem_cache_store, quot;localhostquot;
Or subclass ActiveSupport::Cache::Store
and implement read, write, delete and delete_matched methods
New!




A few other tidbits
rake rails:freeze:edge RELEASE=1.2.0
script/plugin install
              supports
          -e for svn export
and plugins hosted in Git repositories
script/dbconsole
>> quot; A string full of       white    spaces   quot;.squish
=> quot;A string full of white spacesquot;
Resources

• http://weblog.rubyonrails.com/2008/6/1/rails-2-1-time-zones-
 dirty-caching-gem-dependencies-caching-etc

• Ryan Bates’ Railscasts
• Ryan Daigle’s feature introductions
• Ruby on Rails 2.1: What’s New? by Carlos Brando
Thanks for listening




     http://keithpitty.com

More Related Content

What's hot

Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REXSaewoong Lee
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStackBram Vogelaar
 
VCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to FastlyVCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to FastlyFastly
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restartFastly
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stackBram Vogelaar
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesBram Vogelaar
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopLorin Hochstein
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to CeleryIdan Gazit
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talkLocaweb
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparisonHiroshi Nakamura
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in VaultGlynnForrest
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricksjimi-c
 

What's hot (20)

Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Introduction to Celery
Introduction to CeleryIntroduction to Celery
Introduction to Celery
 
VCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to FastlyVCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to Fastly
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restart
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
Django Celery
Django Celery Django Celery
Django Celery
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to Celery
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talk
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in Vault
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
 

Viewers also liked

Seeds And Art
Seeds And ArtSeeds And Art
Seeds And Artcrisman
 
Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?Keith Pitty
 
Clio Final Project 12 10 07
Clio Final Project 12 10 07Clio Final Project 12 10 07
Clio Final Project 12 10 07guest74fc66
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerKeith Pitty
 
The Only Way to Test!
The Only Way to Test!The Only Way to Test!
The Only Way to Test!Keith Pitty
 
Very Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian ProjectVery Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian Projectyouthelectronix
 

Viewers also liked (8)

Seeds And Art
Seeds And ArtSeeds And Art
Seeds And Art
 
Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?
 
Clio Final Project 12 10 07
Clio Final Project 12 10 07Clio Final Project 12 10 07
Clio Final Project 12 10 07
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby Tracker
 
BudgetLevyCycle07
BudgetLevyCycle07BudgetLevyCycle07
BudgetLevyCycle07
 
Ruby Australia
Ruby AustraliaRuby Australia
Ruby Australia
 
The Only Way to Test!
The Only Way to Test!The Only Way to Test!
The Only Way to Test!
 
Very Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian ProjectVery Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian Project
 

Similar to Rails 2.1 Features: Time Zones, Dirty Tracking, Gems, More

Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloudKyle Rames
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardSV Ruby on Rails Meetup
 
glance replicator
glance replicatorglance replicator
glance replicatoririx_jp
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
Bdc from bare metal to k8s
Bdc   from bare metal to k8sBdc   from bare metal to k8s
Bdc from bare metal to k8sChris Adkin
 
How we use and deploy Varnish at Opera
How we use and deploy Varnish at OperaHow we use and deploy Varnish at Opera
How we use and deploy Varnish at OperaCosimo Streppone
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
Fullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endFullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endEzequiel Maraschio
 

Similar to Rails 2.1 Features: Time Zones, Dirty Tracking, Gems, More (20)

Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloud
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
glance replicator
glance replicatorglance replicator
glance replicator
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
Capistrano
CapistranoCapistrano
Capistrano
 
Otimizando seu projeto Rails
Otimizando seu projeto RailsOtimizando seu projeto Rails
Otimizando seu projeto Rails
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Bdc from bare metal to k8s
Bdc   from bare metal to k8sBdc   from bare metal to k8s
Bdc from bare metal to k8s
 
Chef solo the beginning
Chef solo the beginning Chef solo the beginning
Chef solo the beginning
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
How we use and deploy Varnish at Opera
How we use and deploy Varnish at OperaHow we use and deploy Varnish at Opera
How we use and deploy Varnish at Opera
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Fullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endFullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-end
 

Recently uploaded

Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionMintel Group
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / NcrCall Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncrdollysharma2066
 
India Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample ReportIndia Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample ReportMintel Group
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africaictsugar
 
8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCRashishs7044
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Seta Wicaksana
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024Matteo Carbone
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadAyesha Khan
 

Recently uploaded (20)

Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted Version
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / NcrCall Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 
India Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample ReportIndia Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample Report
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africa
 
8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
 

Rails 2.1 Features: Time Zones, Dirty Tracking, Gems, More

  • 1. What’s new in Rails 2.1? Keith Pitty Sydney Rails Meetup 11 June 2008
  • 2.
  • 5. Major features • Time zones • Dirty tracking • Gem dependencies • Named scope • UTC-based migrations • Better caching
  • 7. $ rake -T time (in /Users/keithpitty/work/rails2.1demo) rake time:zones:all # Displays names of all time zones recognized by the... rake time:zones:local # Displays names of time zones recognized by the Rai... rake time:zones:us # Displays names of US time zones recognized by the ...
  • 8. $ rake time:zones:local * UTC +10:00 * Brisbane Canberra Guam Hobart Melbourne Port Moresby Sydney Vladivostok
  • 10. Times now stored in UTC in the db but displayed using the default time zone
  • 11. Warning! If upgrading, times will need to be converted to UTC
  • 12. Example Add time zone support to users
  • 13. Add time_zone to User model
  • 15. <h1>Sign up as a new user</h1> <% @user.password = @user.password_confirmation = nil %> <%= error_messages_for :user %> <% form_for :user, :url => users_path do |f| -%> <p><label for=quot;loginquot;>Login</label><br/> <%= f.text_field :login %></p> <p><label for=quot;emailquot;>Email</label><br/> <%= f.text_field :email %></p> <p><label for=quot;passwordquot;>Password</label><br/> <%= f.password_field :password %></p> <p><label for=quot;password_confirmationquot;>Confirm Password</ label><br/> <%= f.password_field :password_confirmation %></p> <p><label for=quot;time_zonequot;>Time zone</label><br/> <%= f.time_zone_select :time_zone, TimeZone.all %> <p><%= submit_tag 'Sign up' %></p> <% end -%>
  • 16. Use before_filter to set time zone in ApplicationController
  • 17. class ApplicationController < ActionController::Base helper :all protect_from_forgery include AuthenticatedSystem before_filter :set_user_time_zone private def set_user_time_zone Time.zone = current_user.time_zone if logged_in? end end
  • 19. $ ./script/console Loading development environment (Rails 2.1.0) >> Beer.find :first => #<Beer id: 1, name: quot;Coopers Sparkling Alequot;, created_at: quot;2008-06-05 11:31:55quot;, updated_at: quot;2008-06-05 11:31:55quot;> >> b.changed? => false >> b.name = quot;Coopers Pale Alequot; => quot;Coopers Pale Alequot; >> b.changed? => true >> b.changed => [quot;namequot;] >> b.name_changed? => true >> b.name_was => quot;Coopers Sparkling Alequot; >> b.changes => {quot;namequot;=>[quot;Coopers Sparkling Alequot;, quot;Coopers Pale Alequot;]} >> b.save => true >> b.changed? => false
  • 20. Partial updates by default in new Rails 2.1 apps
  • 21. SQL (0.000138) BEGIN Beer Update (0.000304) UPDATE `beers` SET `updated_at` = '2008-06-05 11:38:01', `name` = 'Coopers Pale Ale' WHERE `id` = 1 SQL (0.005019) COMMIT
  • 22. Warning! Updates via other than attr= writer
  • 23. >> b.name_will_change! => quot;Coopers Pale Alequot; >> b.name.upcase! => quot;COOPERS PALE ALEquot; >> b.name_change => [quot;Coopers Pale Alequot;, quot;COOPERS PALE ALEquot;]
  • 25. $ rake -T gem (in /Users/keithpitty/work/rails2.1demo) rake gems # List the gems that this rails application ... rake gems:build # Build any native extensions for unpacked gems rake gems:install # Installs all required gems for this applic... rake gems:unpack # Unpacks the specified gem into vendor/gems. rake gems:unpack:dependencies # Unpacks the specified gems and its depende... rake rails:freeze:gems # Lock this application to the current gems ...
  • 26. # environment.rb # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| config.time_zone = 'Sydney' config.action_controller.session = { :session_key => '_rails2.1demo_session', :secret => 'f4a5c1596f8fff01033b7417629c47fb6344748864b8f3a25fc6884b1ea41d214642f8eba01aa274ef9d128 1fc6cdc23bc33ea57ac66878a7b1164b96d875343' } config.gem quot;hpricotquot;, :version => '0.6', :source => quot;http://code.whytheluckystiff.netquot; config.gem quot;aws-s3quot;, :lib => quot;aws/s3quot; end
  • 27. $ rake gems (in /Users/keithpitty/work/rails2.1demo) [I] hpricot = 0.6 [ ] aws-s3 I = Installed F = Frozen
  • 30. $ rake gems:unpack GEM=hpricot
  • 34. $ rake gems RAILS_ENV='test' (in /Users/keithpitty/work/rails2.1demo) [I] hpricot = 0.6 [ ] aws-s3 [ ] mocha I = Installed F = Frozen
  • 36. class Beer < ActiveRecord::Base named_scope :available, :conditions => {:available => true} named_scope :unavailable, :conditions => {:available => false} named_scope :heavy, :conditions => {:full_strength => true} named_scope :light, :conditions => {:full_strength => false} named_scope :cats_piss, :conditions => {:rating => 0..3} named_scope :drinkable, :conditions => ['rating > 3'] named_scope :minimum_rating, lambda { |min_rating| { :conditions => ['rating >= ?', min_rating] } } named_scope :rated, lambda { |rating| { :conditions => ['rating = ?', rating] } } named_scope :awesome, lambda { |*args| { :conditions => ['rating >= ?', (args.first || 9)] } } end
  • 37. >> Beer.count => 15 >> Beer.available.count => 9 >> Beer.heavy.available.count => 8 >> Beer.heavy.available.drinkable.count => 6 >> Beer.heavy.available.minimum_rating(7).count => 5 >> Beer.heavy.available.awesome.count => 3 >> Beer.heavy.available.awesome(10).count => 1
  • 38. >> Beer.heavy.available.awesome(10) => [#<Beer id: 888319404, name: quot;Coopers Sparkling Alequot;, brewer: quot;Coopersquot;, rating: 10, available: true, full_strength: true, created_at: quot;2008-06-08 07:13:17quot;, updated_at: quot;2008-06-08 07:13:17quot;>]
  • 39. >> Beer.rated(0) => [#<Beer id: 177722761, name: quot;Fosters Lagerquot;, brewer: quot;Fostersquot;, rating: 0, available: false, full_strength: true, created_at: quot;2008-06-08 07:13:17quot;, updated_at: quot;2008-06-08 07:13:17quot;>]
  • 40. Also: named scope extensions, anonymous scopes
  • 42.
  • 43. Migration prefix no longer simply sequential
  • 44. Migration prefix now uses UTC timestamp
  • 45. mysql> select * from schema_migrations; +----------------+ | version | +----------------+ | 20080604194357 | | 20080604195453 | | 20080605112923 | +----------------+ 3 rows in set (0.00 sec)
  • 46. Especially helpful for teams (avoids most conflicts)
  • 47. Also helpful when working on branches
  • 48. Migrations are applied intelligently
  • 49. Also: change_table method introduced to migrations
  • 51. Specify preferred caching engine in environment.rb
  • 52. # Following options supplied in Rails 2.1: ActionController::Base.cache_store = memory_store ActionController::Base.cache_store = file_store, quot;path/to/cache/directoryquot; ActionController::Base.cache_store = drb_store, quot;druby://localhost:9192quot; ActionController::Base.cache_store = mem_cache_store, quot;localhostquot;
  • 53. Or subclass ActiveSupport::Cache::Store and implement read, write, delete and delete_matched methods
  • 56. script/plugin install supports -e for svn export and plugins hosted in Git repositories
  • 58. >> quot; A string full of white spaces quot;.squish => quot;A string full of white spacesquot;
  • 59. Resources • http://weblog.rubyonrails.com/2008/6/1/rails-2-1-time-zones- dirty-caching-gem-dependencies-caching-etc • Ryan Bates’ Railscasts • Ryan Daigle’s feature introductions • Ruby on Rails 2.1: What’s New? by Carlos Brando
  • 60. Thanks for listening http://keithpitty.com