Rails 4 New Features
Noisebridge Ruby and Rails Class
Major New Features
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
Automate efficient cache expiration when using nested fragments aka "Russian Doll Caching"
Use with Rails 3.2: https://github.com/rails/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
Stream data to client with utmost flexibility
Unlike other new features, this one is not packaged for use with Rails 3.2
Feature: Strong parameters
New mechanism for mass assignment control.
attr_accessiblein models. Instead, strong parameters DSL in controllers.
Use with Rails 3.2: https://github.com/rails/strong_parameters
Strong parameters, continued
- Rails < 3.2.3 allowed mass assignment of arbitrary attributes by default
- @homakov calls attention to security implications of this behavior - https://github.com/rails/rails/issues/5228
- Rails committers close @homakov's ticket for various reasons.
- @homakov discovers and exploits vulnerability in GitHub caused by Rails' default behavior - https://github.com/rails/rails/commit/b839657
- Rails team rushes to ship point release that prohibits mass assignment of attributes by default (Rails 3.2.3)
- @wycats proposes Improving Mass Assignment, provokes discussion.
- @dhh releases https://github.com/rails/strong_parameters
Strong parameters, continued, continued
More flexible than
Strong Parameters screencast by RailsCasts Pro
Use with Rails 3.2: https://github.com/rails/turbolinks
Seriously. Numbers. Use them. by Steve Klabnik
Other new features
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
Relation#lastorder by id
Relation#ordertakes 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
No need to delete public/index.html anymore !
before_action loads models in scaffolded controllers
Slims down the controller action methods
Better exceptions pages
Routing errors show routes table
Pure-Ruby template handler
Useful for rendering data
What's New in Rails 4 screen cast by RailsCasts
Rails 4: What`s New blog post by Steve Schwartz
Rails 4 Whirlwind Tour video presentation by Andy Lindeman