SlideShare a Scribd company logo
Rails 3.1
  Lori Olson
 Confoo 2012
 Montreal, QC
Another new version of Rails.
 Delightful. And terrifying.
  What's changed this time?
Summary


• jQuery
• CoffeeScript
• SASS
• Asset Pipeline
• Miscellaneous cool stuff
But...



• What about Rails 3.2?
 • only released a few weeks ago
 • not nearly as many scary changes
jQuery
What you HAVE to know



• How to go back to Prototype (not
  recommended
 • rails new my_app -j prototype
Differences

• Gemfile
 gem ā€˜jquery-rails’
• application.js
 //= require jquery
 //= require jquery_ujs
But... Why jQuery?
Rails 3.1
CoffeeScript
What you HAVE to know

• Nothing
• Absolutely not required
• Just remove one line from Gemfile
 • gem 'coffee-rails'
 • And you don’t even have to do this
Thomas Fuchs on
      CoffeeScript

• May 2011 - "I just like javascript too
  much to have a use for that, but I
  understand why other people might
  like it"
• Aug 2011 - There, it happened.
  Mistakenly typed CoffeeScript in a .js
  file. So easy to pick up, and so natural.
CoffeeScript Resources
• Railscasts
  • CoffeeScript Basics
  •   http://railscasts.com/episodes/267-coffeescript-basics

• Peepcode
  • Meet CoffeeScript
  • http://peepcode.com/products/coffeescript
• Books
  • Pragmatic Programmers - CoffeeScript
  • O’Reilly - The Little Book on CoffeeScript
SASS
What you HAVE to know

• Nothing
• Absolutely not required
• Just remove one line from your Gemfile
 • gem 'sass-rails'
 • And you don’t even have to do that
Is it SASS or SCSS?


• Sass is the older style HAML-like
  indented syntax
• SCSS is the new main syntax, which is a
  superset of CSS3
Why SASS?
• Variables
• Nesting
 • DRY up your styles
• Mixins
 • reusable chunks
 • with arguments!
• Selector Inheritance
Alternatives to SASS

• Less
• HSS
• Other, technology specific
 • XCSS (PHP)
 • CleverCss (Python)
 • CSS Crush (PHP)
Asset Pipeline
assets dir
assets dir
assets dir
assets dir
js manifest
• Powered by - Sprockets
• application.js
  // FIXME: Tell people that this is a manifest
  file, real code should go into discrete files
  //
  //= require jquery
  //= require jquery_ujs
  //= require_tree .
SASS - no sprockets



• probably don’t want to use manifests
• use @import, or your variables and
  scopes will not work
Dev vs Production


• To precompile, or not to precompile
• Heroku
 • Cedar stack
 • counter-intuitive settings
Compression



• Uglifier (for javascript)
• SCSS (for css)
But, Why?
Identity Map
enabling


• application.rb
  # Enable IdentityMap for Active Record,
  to disable set to false or remove the line
  below.
  config.active_record.identity_map = true
problems



• associations
• STI
• tests
nested
has_many :through
class Project < ActiveRecord::Base
 has_many :tasks
 has_many :assignments, :through => :tasks
 has_many :users, :through => :assignments
end
Migrations
class CreateProjects < ActiveRecord::Migration

 def change

  create_table :projects do |t|

   t.string :name

   t.timestamps

  end

 end

end
HTTP Streaming
requirements


• Ruby 1.9.2 (min)
• Web server support
 • nginx
 • unicorn
Examples
New App
Upgrade
Bundler



• Did you know... you can use bundler all
  the way down to Rails 2.1 apps?
Add Bundler




• http://youtu.be/7UzGdqaDnp8
• Upgrade the Gemfile

• Config file changes

• Move the assets
Configs


• boot.rb
• config.rb
• development.rb
• production.rb
Assets


• Move asset folders
• Fix image references
• Manifests
• stylesheet and javascript tag references
Upgrade Demo



• Upgrading a Rails 2.1 app to Rails 3.1 in
  1…

More Related Content

What's hot (20)

KEY
Why ruby and rails
Reuven Lerner
Ā 
KEY
SFJS 6-19-2012
Adam Christian
Ā 
PDF
SF Hadoop Users Group August 2014 Meetup Slides
Yash Ranadive
Ā 
PDF
PharoDAYS 2015: On Relational Databases by Guille Polito
Pharo
Ā 
PPTX
Intro to Clojure 4 Developers
Nola Stowe
Ā 
PDF
Coffeescript
Burke Libbey
Ā 
PPTX
Javascript now and in the future
Denis Stoyanov
Ā 
KEY
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
Ā 
PDF
Gatsby vs. Next.js
Borek Bernard
Ā 
PPTX
JS Fest 2018. АлексанГр Дкачков. WebAssembly vs JavaScript
JSFestUA
Ā 
PPTX
Through Meteor to the stars - Developing full-stack SPA's with meteor.js
Wekoslav Stefanovski
Ā 
PPTX
Can i Get C# for Free ?
Welly Tambunan
Ā 
PPTX
Lisp in the Cloud
Mike Travers
Ā 
PDF
[Rakuten TechConf2014] [C-2] Big Data for eBooks and eReaders
Rakuten Group, Inc.
Ā 
PDF
Masterin Large Scale Java Script Applications
Fabian Jakobs
Ā 
PDF
Why I will never write JavaScript ever again*
The Wolff
Ā 
PDF
Ingesting Banner output Schedule Classes into Cascade Server (In Java - Web S...
hannonhill
Ā 
PDF
Ruby on Rails Workshop
Yos Riady
Ā 
PDF
[CocoaHeads Tricity] Michał Zygar - Consuming API
CocoaHeads Tricity
Ā 
PDF
Server Check.in case study - Drupal and Node.js
Jeff Geerling
Ā 
Why ruby and rails
Reuven Lerner
Ā 
SFJS 6-19-2012
Adam Christian
Ā 
SF Hadoop Users Group August 2014 Meetup Slides
Yash Ranadive
Ā 
PharoDAYS 2015: On Relational Databases by Guille Polito
Pharo
Ā 
Intro to Clojure 4 Developers
Nola Stowe
Ā 
Coffeescript
Burke Libbey
Ā 
Javascript now and in the future
Denis Stoyanov
Ā 
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
Ā 
Gatsby vs. Next.js
Borek Bernard
Ā 
JS Fest 2018. АлексанГр Дкачков. WebAssembly vs JavaScript
JSFestUA
Ā 
Through Meteor to the stars - Developing full-stack SPA's with meteor.js
Wekoslav Stefanovski
Ā 
Can i Get C# for Free ?
Welly Tambunan
Ā 
Lisp in the Cloud
Mike Travers
Ā 
[Rakuten TechConf2014] [C-2] Big Data for eBooks and eReaders
Rakuten Group, Inc.
Ā 
Masterin Large Scale Java Script Applications
Fabian Jakobs
Ā 
Why I will never write JavaScript ever again*
The Wolff
Ā 
Ingesting Banner output Schedule Classes into Cascade Server (In Java - Web S...
hannonhill
Ā 
Ruby on Rails Workshop
Yos Riady
Ā 
[CocoaHeads Tricity] Michał Zygar - Consuming API
CocoaHeads Tricity
Ā 
Server Check.in case study - Drupal and Node.js
Jeff Geerling
Ā 

Similar to Rails 3.1 (20)

PDF
Create a new project in ROR
akankshita satapathy
Ā 
PDF
Rails 3 : Cool New Things
Y. Thong Kuah
Ā 
PDF
Migrating Legacy Rails Apps to Rails 3
Clinton Dreisbach
Ā 
PDF
Frozen Rails Slides
carllerche
Ā 
KEY
Intro to Ruby on Rails
rschmukler
Ā 
PDF
Rails - getting started
True North
Ā 
PDF
Web Development using Ruby on Rails
Avi Kedar
Ā 
PDF
Rails 3.1 Awesomeness - what's new
Dynamic Clarity
Ā 
PDF
Aspose pdf
Jim Jones
Ā 
PPT
Rails 101
The Active Network
Ā 
PDF
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
Ā 
PPTX
Ruby on Rails : First Mile
Gourab Mitra
Ā 
KEY
Rapid Prototyping FTW!!!
cloudbring
Ā 
PPTX
Rubyonrails 120409061835-phpapp02
sagaroceanic11
Ā 
KEY
An introduction to Rails 3
Blazing Cloud
Ā 
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
Ā 
PDF
Rails 3.1 Asset Pipeline
eallam
Ā 
KEY
Supa fast Ruby + Rails
Jean-Baptiste Feldis
Ā 
KEY
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
Ā 
PDF
Railsguide
lanlau
Ā 
Create a new project in ROR
akankshita satapathy
Ā 
Rails 3 : Cool New Things
Y. Thong Kuah
Ā 
Migrating Legacy Rails Apps to Rails 3
Clinton Dreisbach
Ā 
Frozen Rails Slides
carllerche
Ā 
Intro to Ruby on Rails
rschmukler
Ā 
Rails - getting started
True North
Ā 
Web Development using Ruby on Rails
Avi Kedar
Ā 
Rails 3.1 Awesomeness - what's new
Dynamic Clarity
Ā 
Aspose pdf
Jim Jones
Ā 
Rails 101
The Active Network
Ā 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
Ā 
Ruby on Rails : First Mile
Gourab Mitra
Ā 
Rapid Prototyping FTW!!!
cloudbring
Ā 
Rubyonrails 120409061835-phpapp02
sagaroceanic11
Ā 
An introduction to Rails 3
Blazing Cloud
Ā 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
Ā 
Rails 3.1 Asset Pipeline
eallam
Ā 
Supa fast Ruby + Rails
Jean-Baptiste Feldis
Ā 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
Ā 
Railsguide
lanlau
Ā 
Ad

More from Lori Olson (7)

PDF
Do The Work
Lori Olson
Ā 
KEY
Rockstars & Consultants, who needs 'em
Lori Olson
Ā 
KEY
RubyMotion Introduction
Lori Olson
Ā 
KEY
Mobile rage
Lori Olson
Ā 
KEY
Maps and Scale
Lori Olson
Ā 
KEY
Rockstars & Consultants - who needs 'em
Lori Olson
Ā 
PDF
Powerful UX, not just for desktops anymore
Lori Olson
Ā 
Do The Work
Lori Olson
Ā 
Rockstars & Consultants, who needs 'em
Lori Olson
Ā 
RubyMotion Introduction
Lori Olson
Ā 
Mobile rage
Lori Olson
Ā 
Maps and Scale
Lori Olson
Ā 
Rockstars & Consultants - who needs 'em
Lori Olson
Ā 
Powerful UX, not just for desktops anymore
Lori Olson
Ā 
Ad

Recently uploaded (20)

PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
Ā 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
Ā 
PDF
The Future of Artificial Intelligence (AI)
Mukul
Ā 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
Ā 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
Ā 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
Ā 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
Ā 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
Ā 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
Ā 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
Ā 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
Ā 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
Ā 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
Ā 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
Ā 
The Future of Artificial Intelligence (AI)
Mukul
Ā 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
Simple and concise overview about Quantum computing..pptx
mughal641
Ā 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
Ā 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
Ā 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
Ā 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
Ā 
Researching The Best Chat SDK Providers in 2025
Ray Fields
Ā 
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
Ā 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
Ā 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
Ā 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
Ā 

Rails 3.1

Editor's Notes

  • #2: \n
  • #3: \n
  • #4: \n
  • #5: \n
  • #6: So, out with the old, and in with the new. Prototype was the default Javascript library in Rails since the very beginning. There have been rumblings for several (intermediate) versions, but they finally pulled the trigger and did it.\n
  • #7: However, if you just HAVE to use Prototype, it is just a simple -j option away. The choice of Javascript libs is now tucked away into a couple of gems\n\n\n
  • #8: gem &apos;jquery-rails&apos; or gem &apos;prototype-rails&apos; will show up in your Gemfile\nAnd prototype or jquery js will be included via your application javascript manifest file\n- But, I get ahead of myself\n\n
  • #9: Almost 10x more popular than Prototype\n\nPopularity == ecosystem\n\nVersioning... rails dictates which jQuery version now, which is better\n
  • #10: Infographic\nfile:///Volumes/loriolson/Confoo/Javascript%20Frameworks%20and%20jQuery%20(Infographic)%20%7C%20Web%20Resources%20%7C%20WebAppers.webarchive\n
  • #11: \n
  • #12: But it&amp;#x2019;s important to note that CoffeeScript, while defined as a dependency by default in Rails 3.1, is not a requirement. You can just stick with pure Javascript (and jQuery) and call it done.\n\nNow, I consider myself just a dabbler in CoffeeScript, so I won&amp;#x2019;t spend a lot of time on it.\n\n
  • #13: Thomas Fuchs, author of the Scriptaculous framework, co-author of the JavaScript Performance Rocks! ebook had this to say about CoffeeScript\n
  • #14: However, if you really want to learn it, and I suggest you do, there are some great resources out there. \n
  • #15: Syntactically Awesome Stylesheets\n
  • #16: \n
  • #17: Guess which one is recommended? ;-)\n
  • #18: \n
  • #19: \n
  • #20: It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines\n
  • #21: So, the assets (images, javascripts, &amp; stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
  • #22: So, the assets (images, javascripts, &amp; stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
  • #23: So, the assets (images, javascripts, &amp; stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
  • #24: So, the assets (images, javascripts, &amp; stylesheets) have been tucked under public, all this time.\n\nNow, they are slotted in under the app/assets directory\n
  • #25: \n
  • #26: \n
  • #27: generate something to run on heroku to demo diff\n
  • #28: \n
  • #29: Average load time\nNumber of resource requests\nCDN\n\n
  • #30: Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion.\nRails 3.1 comes with the identity map turned off by default. There are issues...\n
  • #31: \n
  • #32: \n
  • #33: \n
  • #34: Didn&amp;#x2019;t used to be able to nest these\n\nWord of warning. You may, or may not run into problems on non-default databases. And I can practically guarantee the you will have problems if you used this in conjunction with a legacy database with composite primary keys.\n
  • #35: change\n
  • #36: Instead of up and down. This works for straight-forward migrations, but if you are doing something special, you will probably still want up &amp; down.\n
  • #37: HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it.\n
  • #38: \n
  • #39: \n
  • #40: \n
  • #41: \n
  • #42: \n
  • #43: \n
  • #44: \n
  • #45: \n
  • #46: \n
  • #47: \n