Slide 1

Slide 1 text

Rails 3.1 Lori Olson Confoo 2012 Montreal, QC

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

jQuery

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

But... Why jQuery?

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

CoffeeScript

Slide 11

Slide 11 text

• 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

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

SASS

Slide 15

Slide 15 text

• 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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Asset Pipeline

Slide 20

Slide 20 text

assets dir

Slide 21

Slide 21 text

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 .

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

But, Why?

Slide 26

Slide 26 text

Identity Map

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

problems • associations • STI • tests

Slide 29

Slide 29 text

nested has_many :through

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

Migrations

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

HTTP Streaming

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Examples

Slide 36

Slide 36 text

New App

Slide 37

Slide 37 text

Upgrade

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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