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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. But... Why jQuery?

    View full-size slide

  8. CoffeeScript

    View full-size slide

  9. • 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 full-size slide

  10. 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 full-size slide

  11. 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 full-size slide

  12. • 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 full-size slide

  13. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  16. Asset Pipeline

    View full-size slide

  17. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  21. Identity Map

    View full-size slide

  22. • 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 full-size slide

  23. problems
    • associations
    • STI
    • tests

    View full-size slide

  24. nested
    has_many :through

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. HTTP Streaming

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide