123456789_123456789_123456789_123456789_123456789_

DO NOT READ THIS FILE ON GITHUB, GUIDES ARE PUBLISHED ON https://guides.rubyonrails.org.

Ruby on Rails 5.0 Release Notes

Highlights in Rails 5.0:

These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the changelogs or check out the list of commits in the main Rails repository on GitHub.


Upgrading to Rails 5.0

If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 4.2 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 5.0. A list of things to watch out for when upgrading is available in the Upgrading Ruby on Rails guide.

Major Features

Action Cable

Action Cable is a new framework in Rails 5. It seamlessly integrates WebSockets with the rest of your Rails application.

Action Cable allows for real-time features to be written in Ruby in the same style and form as the rest of your Rails application, while still being performant and scalable. It's a full-stack offering that provides both a client-side JavaScript framework and a server-side Ruby framework. You have access to your full domain model written with Active Record or your ORM of choice.

See the Action Cable Overview guide for more information.

API Applications

Rails can now be used to create slimmed down API only applications. This is useful for creating and serving APIs similar to Twitter or GitHub API, that can be used to serve public-facing, as well as, for custom applications.

You can generate a new api Rails app using:

$ rails new my_api --api

This will do three main things:

The application provides a base for APIs, that can then be configured to pull in functionality as suitable for the application's needs.

See the Using Rails for API-only Applications guide for more information.

Active Record attributes API

Defines an attribute with a type on a model. It will override the type of existing attributes if needed. This allows control over how values are converted to and from SQL when assigned to a model. It also changes the behavior of values passed to ActiveRecord::Base.where, which let's use our domain objects across much of Active Record, without having to rely on implementation details or monkey patching.

Some things that you can achieve with this:

# db/schema.rb
create_table :store_listings, force: true do |t|
  t.decimal :price_in_cents
  t.string :my_string, default: "original default"
end
# app/models/store_listing.rb
class StoreListing < ActiveRecord::Base
end
store_listing = StoreListing.new(price_in_cents: '10.1')

# before
store_listing.price_in_cents # => BigDecimal.new(10.1)
StoreListing.new.my_string # => "original default"

class StoreListing < ActiveRecord::Base
  attribute :price_in_cents, :integer # custom type
  attribute :my_string, :string, default: "new default" # default value
  attribute :my_default_proc, :datetime, default: -> { Time.now } # default value
  attribute :field_without_db_column, :integer, array: true
end

# after
store_listing.price_in_cents # => 10
StoreListing.new.my_string # => "new default"
StoreListing.new.my_default_proc # => 2015-05-30 11:04:48 -0600
model = StoreListing.new(field_without_db_column: ["1", "2", "3"])
model.attributes # => {field_without_db_column: [1, 2, 3]}

Creating Custom Types:

You can define your own custom types, as long as they respond to the methods defined on the value type. The method deserialize or cast will be called on your type object, with raw input from the database or from your controllers. This is useful, for example, when doing custom conversion, like Money data.

Querying:

When ActiveRecord::Base.where is called, it will use the type defined by the model class to convert the value to SQL, calling serialize on your type object.

This gives the objects ability to specify, how to convert values when performing SQL queries.

Dirty Tracking:

The type of an attribute is allowed to change how dirty tracking is performed.

See its documentation for a detailed write up.

Test Runner

A new test runner has been introduced to enhance the capabilities of running tests from Rails. To use this test runner simply type bin/rails test.

Test Runner is inspired by RSpec, minitest-reporters, maxitest and others. It includes some of these notable advancements:

Railties

Please refer to the Changelog for detailed changes.

Removals

Deprecations

Notable changes

Action Pack

Please refer to the Changelog for detailed changes.

Removals

Deprecations

Notable changes

Action View

Please refer to the Changelog for detailed changes.

Removals

Notable Changes

Action Mailer

Please refer to the Changelog for detailed changes.

Removals

Notable changes

Active Record

Please refer to the Changelog for detailed changes.

Removals

Deprecations

Notable changes

Active Model

Please refer to the Changelog for detailed changes.

Removals

Deprecations

Notable changes

Active Job

Please refer to the Changelog for detailed changes.

Notable changes

Active Support

Please refer to the Changelog for detailed changes.

Removals

Deprecations

Notable changes

Credits

See the full list of contributors to Rails for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.