Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails 3.1 - Confoo

Lori M Olson
February 29, 2012

Rails 3.1 - Confoo

Another new version of Rails. Delightful. And terrifying. What's changed this time? Fear Not!

We'll be reviewing the changes and additions to Rails 3.1, giving you a walk-through of what it all means (asset pipeline, what?), in the context of a brand new app, and an older app that will need to be upgraded.

Lori M Olson

February 29, 2012
Tweet

More Decks by Lori M Olson

Other Decks in Programming

Transcript

  1. Rails 3.1
    Lori Olson
    Confoo 2012
    Montreal, QC

    View Slide

  2. Another new version of Rails.
    Delightful. And terrifying.
    What's changed this time?

    View Slide

  3. Summary
    • jQuery
    • CoffeeScript
    • SASS
    • Asset Pipeline
    • Miscellaneous cool stuff

    View Slide

  4. But...
    • What about Rails 3.2?
    • only released a few weeks ago
    • not nearly as many scary changes

    View Slide

  5. jQuery

    View Slide

  6. • How to go back to Prototype (not
    recommended
    • rails new my_app -j prototype
    What you HAVE to know

    View Slide

  7. Differences
    • Gemfile
    gem ‘jquery-rails’
    • application.js
    //= require jquery
    //= require jquery_ujs

    View Slide

  8. But... Why jQuery?

    View Slide

  9. View Slide

  10. CoffeeScript

    View Slide

  11. • Nothing
    • Absolutely not required
    • Just remove one line from Gemfile
    • gem 'coffee-rails'
    • And you don’t even have to do this
    What you HAVE to know

    View Slide

  12. 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.

    View Slide

  13. 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

    View Slide

  14. SASS

    View Slide

  15. • Nothing
    • Absolutely not required
    • Just remove one line from your Gemfile
    • gem 'sass-rails'
    • And you don’t even have to do that
    What you HAVE to know

    View Slide

  16. 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

    View Slide

  17. Why SASS?
    • Variables
    • Nesting
    • DRY up your styles
    • Mixins
    • reusable chunks
    • with arguments!
    • Selector Inheritance

    View Slide

  18. Alternatives to SASS
    • Less
    • HSS
    • Other, technology specific
    • XCSS (PHP)
    • CleverCss (Python)
    • CSS Crush (PHP)

    View Slide

  19. Asset Pipeline

    View Slide

  20. assets dir

    View Slide

  21. 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 .

    View Slide

  22. SASS - no sprockets
    • probably don’t want to use manifests
    • use @import, or your variables and
    scopes will not work

    View Slide

  23. Dev vs Production
    • To precompile, or not to precompile
    • Heroku
    • Cedar stack
    • counter-intuitive settings

    View Slide

  24. Compression
    • Uglifier (for javascript)
    • SCSS (for css)

    View Slide

  25. But, Why?

    View Slide

  26. Identity Map

    View Slide

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

    View Slide

  28. problems
    • associations
    • STI
    • tests

    View Slide

  29. nested
    has_many :through

    View Slide

  30. class Project < ActiveRecord::Base
    has_many :tasks
    has_many :assignments, :through => :tasks
    has_many :users, :through => :assignments
    end

    View Slide

  31. Migrations

    View Slide

  32. class CreateProjects < ActiveRecord::Migration
    def change
    create_table :projects do |t|
    t.string :name
    t.timestamps
    end
    end
    end

    View Slide

  33. HTTP Streaming

    View Slide

  34. requirements
    • Ruby 1.9.2 (min)
    • Web server support
    • nginx
    • unicorn

    View Slide

  35. Examples

    View Slide

  36. New App

    View Slide

  37. Upgrade

    View Slide

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

    View Slide

  39. • http://youtu.be/7UzGdqaDnp8
    Add Bundler

    View Slide

  40. • Upgrade the Gemfile
    • Config file changes
    • Move the assets

    View Slide

  41. Configs
    • boot.rb
    • config.rb
    • development.rb
    • production.rb

    View Slide

  42. Assets
    • Move asset folders
    • Fix image references
    • Manifests
    • stylesheet and javascript tag references

    View Slide

  43. • Upgrading a Rails 2.1 app to Rails 3.1 in
    1…
    Upgrade Demo

    View Slide