Rails 3.1 - Confoo

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.

B36ea58289890176b6170e382b3194fe?s=128

Lori M Olson

February 29, 2012
Tweet

Transcript

  1. Rails 3.1 Lori Olson Confoo 2012 Montreal, QC

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

    this time?
  3. Summary • jQuery • CoffeeScript • SASS • Asset Pipeline

    • Miscellaneous cool stuff
  4. But... • What about Rails 3.2? • only released a

    few weeks ago • not nearly as many scary changes
  5. jQuery

  6. • How to go back to Prototype (not recommended •

    rails new my_app -j prototype What you HAVE to know
  7. Differences • Gemfile gem ‘jquery-rails’ • application.js //= require jquery

    //= require jquery_ujs
  8. But... Why jQuery?

  9. None
  10. CoffeeScript

  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
  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.
  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
  14. SASS

  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
  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
  17. Why SASS? • Variables • Nesting • DRY up your

    styles • Mixins • reusable chunks • with arguments! • Selector Inheritance
  18. Alternatives to SASS • Less • HSS • Other, technology

    specific • XCSS (PHP) • CleverCss (Python) • CSS Crush (PHP)
  19. Asset Pipeline

  20. assets dir

  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 .
  22. SASS - no sprockets • probably don’t want to use

    manifests • use @import, or your variables and scopes will not work
  23. Dev vs Production • To precompile, or not to precompile

    • Heroku • Cedar stack • counter-intuitive settings
  24. Compression • Uglifier (for javascript) • SCSS (for css)

  25. But, Why?

  26. Identity Map

  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
  28. problems • associations • STI • tests

  29. nested has_many :through

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

    :tasks has_many :users, :through => :assignments end
  31. Migrations

  32. class CreateProjects < ActiveRecord::Migration def change create_table :projects do |t|

    t.string :name t.timestamps end end end
  33. HTTP Streaming

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

    nginx • unicorn
  35. Examples

  36. New App

  37. Upgrade

  38. Bundler • Did you know... you can use bundler all

    the way down to Rails 2.1 apps?
  39. • http://youtu.be/7UzGdqaDnp8 Add Bundler

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

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

  42. Assets • Move asset folders • Fix image references •

    Manifests • stylesheet and javascript tag references
  43. • Upgrading a Rails 2.1 app to Rails 3.1 in

    1… Upgrade Demo