Skip to content

Instantly share code, notes, and snippets.

@gkop
Created January 9, 2013 05:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkop/4490770 to your computer and use it in GitHub Desktop.
Save gkop/4490770 to your computer and use it in GitHub Desktop.
Noisebridge Ruby and Rails class 1/8/13: Rails 4 New Features (notes)

Rails 4 New Features

Noisebridge Ruby and Rails Class

2013-01-08

Gabe Kopley

gabe@railsschool.org

www.railsschool.org/l/rails-4-new-features


Major New Features

  • Cache digests

  • ActionController::Live

  • Strong parameters

  • Turbolinks


Creating an Edge Rails App

$ gem install bundler --pre
$ gem install i18n thor thread_safe
$ git clone git://github.com/rails/rails.git
$ rails/railties/bin/rails new <path> --edge
create  
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


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

Background


Strong parameters, continued, continued

More flexible than attr_accessible

(demo)

Strong Parameters screencast by RailsCasts Pro


Feature: Turbolinks


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

(demo)


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

HTML5-specific

  • #date_field

WelcomeController

No need to delete public/index.html anymore !


InfoController


before_action loads models in scaffolded controllers

Slims down the controller action methods

(demo)


Better exceptions pages

  • Prettier

  • Routing errors show routes table

  • (demo)


Pure-Ruby template handler

app/views/foo/show.json.ruby

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