Skip to content

Instantly share code, notes, and snippets.



Created Jan 9, 2013
What would you like to do?
Noisebridge Ruby and Rails class 1/8/13: Rails 4 New Features (notes)

Rails 4 New Features

Noisebridge Ruby and Rails Class


Gabe Kopley

Major New Features

  • Cache digests

  • ActionController::Live

  • Strong parameters

  • Turbolinks

Creating an Edge Rails App

(tested with 1ce304f8165e4a930f1a8fb1f6706e61f6411096)

$ gem install bundler --pre
$ gem install i18n thor thread_safe
$ git clone git://
$ rails/railties/bin/rails new <path> --edge
create  README.rdoc
create  Rakefile

$ cd <path>
$ bundle exec rails --version
Rails 4.0.0.beta

(Note you must use bundle exec or binstubs because Rubygems doesn't know about gems bundled from git)

Feature: Cache digests

Cache digests

Cache digests, continued

Eg. user profile shows his posts and the comments for each post

Profiles, posts, and comments are all fragment cached

  • Expire comment fragment when comment template is changed

  • Expire post fragment when the post template or comment template is changed

  • Expire profile fragment when profile template, post template, or comment template is changed

  • (demo)

Feature: ActionController::Live


  • Stream data to client with utmost flexibility

  • Unlike other new features, this one is not packaged for use with Rails 3.2

  • Detailed post by Tenderlove

  • (demo)

Feature: Strong parameters

Strong parameters

Strong parameters, continued


Strong parameters, continued, continued

More flexible than attr_accessible


Strong Parameters screencast by RailsCasts Pro

Feature: Turbolinks


Other new features

Support for PATCH

Now treats PATCH and PUT requests the same

When updating record, submits forms as "PATCH" requests with _method form parameter


Native support for Postgres hstore

Majorly revised Getting Started Guide

No more scaffolding!

New approach: try something, it doesn't work, make it work, repeat...

Dependency on Ruby > 1.9.3

Gems you develop for Rails 4 can assume Ruby > 1.9.3

Lots of changes to ActiveRecord

See links on last slide for details

  • .all returns relation
  • #update_columns introduced
  • Relation#none introduced
  • Relation#not introduced
  • Relation#first and Relation#last order by id
  • Relation#order takes a hash of columns and their orders
  • Bang methods on relations
  • Whole bunch of deprecations (eg. many dynamic finders)
  • Models don't need to subclass ActiveRecord::Base, can mixin instead
  • ...

New form helpers

  • #collection_checkboxes
  • #collection_radiobuttons


  • #date_field


No need to delete public/index.html anymore !



before_action loads models in scaffolded controllers

Slims down the controller action methods


Better exceptions pages

  • Prettier

  • Routing errors show routes table

  • (demo)

Pure-Ruby template handler


Useful for rendering data

Useful links

Thanks Noisebridge!

Noisebridge logo

If you enjoy the class, please consider making a donation to Noisebridge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment