1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/guides/source/5_0_release_notes.md

32 KiB

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

Ruby on Rails 5.0 Release Notes

Highlights in Rails 5.0:

  • Action Cable
  • Rails API
  • Active Record Attributes API
  • Test Runner
  • Exclusive use of rails CLI over Rake
  • Sprockets 3
  • Turbolinks 5
  • Ruby 2.2.2+ required

These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the change logs 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

Pull Request

ToDo...

Rails API

Pull Request

ToDo...

Active Record attributes API

ToDo...

Test Runner

Pull Request

ToDo...

Railties

Please refer to the Changelog for detailed changes.

Removals

  • Removed debugger support, use byebug instead. debugger is not supported by Ruby 2.2. (commit)

  • Removed deprecated test:all and test:all:db tasks. (commit)

  • Removed deprecated Rails::Rack::LogTailer. (commit)

  • Removed deprecated RAILS_CACHE constant. (commit)

  • Removed deprecated serve_static_assets configuration. (commit)

  • Removed the documentation tasks doc:app, doc:rails, and doc:guides. (commit)

  • Removed Rack::ContentLength middleware from the default stack. (Commit)

Deprecations

  • Deprecated config.static_cache_control in favor of config.public_file_server.headers. (Pull Request)

  • Deprecated config.serve_static_files in favor of config.public_file_server.enabled. (Pull Request)

Notable changes

  • Added Rails test runner bin/rails test. (Pull Request)

  • Newly generated applications and plugins get a README.md in Markdown. (commit, Pull Request)

  • Added bin/rails restart task to restart your Rails app by touching tmp/restart.txt. (Pull Request)

  • Added bin/rails initializers task to print out all defined initializers in the order they are invoked by Rails. (Pull Request)

  • Added bin/rails dev:cache to enable or disable caching in development mode. (Pull Request)

  • Added bin/update script to update the development environment automatically. (Pull Request)

  • Proxy Rake tasks through bin/rails. (Pull Request, Pull Request)

Action Pack

Please refer to the Changelog for detailed changes.

Removals

  • Removed ActionDispatch::Request::Utils.deep_munge. (commit)

  • Removed ActionController::HideActions. (Pull Request)

  • Removed respond_to and respond_with placeholder methods, this functionality has been extracted to the responders gem. (commit)

  • Removed deprecated assertion files. (commit)

  • Removed deprecated usage of string keys in URL helpers. (commit)

  • Removed deprecated only_path option on *_path helpers. (commit)

  • Removed deprecated NamedRouteCollection#helpers. (commit)

  • Removed deprecated support to define routes with :to option that doesn't contain #. (commit)

  • Removed deprecated ActionDispatch::Response#to_ary. (commit)

  • Removed deprecated ActionDispatch::Request#deep_munge. (commit)

  • Removed deprecated ActionDispatch::Http::Parameters#symbolized_path_parameters. (commit)

  • Removed deprecated option use_route in controller tests. (commit)

  • Removed assigns and assert_template. Both methods have been extracted into the rails-controller-testing gem. (Pull Request)

Deprecations

  • Deprecated all *_filter callbacks in favor of *_action callbacks. (Pull Request)

  • Deprecated *_via_redirect integration test methods. Use follow_redirect! manually after the request call for the same behavior. (Pull Request)

  • Deprecated AbstractController#skip_action_callback in favor of individual skip_callback methods. (Pull Request)

  • Deprecated :nothing option for render method. (Pull Request)

  • Deprecated passing first parameter as Hash and default status code for head method. (Pull Request)

  • Deprecated using strings or symbols for middleware class names. Use class names instead. (commit)

  • Deprecated accessing mime types via constants (eg. Mime::HTML). Use the subscript operator with a symbol instead (eg. Mime[:html]). (Pull Request)

  • Deprecated redirect_to :back in favor of redirect_back, which accepts a required fallback_location argument, thus eliminating the possibility of a RedirectBackError. (Pull Request)

Notable changes

  • Added ActionController::Renderer to render arbitrary templates outside controller actions. (Pull Request)

  • Migrating to keyword arguments syntax in ActionController::TestCase and ActionDispatch::Integration HTTP request methods. (Pull Request)

  • Added http_cache_forever to Action Controller, so we can cache a response that never gets expired. (Pull Request)

  • Provide friendlier access to request variants. (Pull Request)

  • For actions with no corresponding templates, render head :no_content instead of raising an error. (Pull Request)

  • Added the ability to override default form builder for a controller. (Pull Request)

  • Added support for API only apps. ActionController::API is added as a replacement of ActionController::Base for this kind of applications. (Pull Request)

  • Make ActionController::Parameters no longer inherits from HashWithIndifferentAccess. (Pull Request)

  • Make it easier to opt in to config.force_ssl and config.ssl_options by making them less dangerous to try and easier to disable. (Pull Request)

  • Added the ability of returning arbitrary headers to ActionDispatch::Static. (Pull Request)

  • Changed the protect_from_forgery prepend default to false. (commit)

  • ActionController::TestCase will be moved to it's own gem in Rails 5.1. Use ActionDispatch::IntegrationTest instead. (commit)

Action View

Please refer to the Changelog for detailed changes.

Removals

  • Removed deprecated AbstractController::Base::parent_prefixes. (commit)

  • Removed ActionView::Helpers::RecordTagHelper, this functionality has been extracted to the record_tag_helper gem. (Pull Request)

  • Removed :rescue_format option for translate helper since it's no longer supported by I18n. (Pull Request)

Notable Changes

  • Changed the default template handler from ERB to Raw. (commit)

  • Collection rendering automatically caches and fetches multiple partials. (Pull Request)

  • Allow defining explicit collection caching using a # Template Collection: ... directive inside templates. (Pull Request)

  • Added wildcard matching to explicit dependencies. (Pull Request)

  • Make disable_with the default behavior for submit tags. Disables the button on submit to prevent double submits. (Pull Request)

Action Mailer

Please refer to the Changelog for detailed changes.

Removals

  • Removed deprecated *_path helpers in email views. (commit)

  • Removed deprecated deliver and deliver! methods. (commit)

Notable changes

  • Template lookup now respects default locale and I18n fallbacks. (commit)

  • Added _mailer suffix to mailers created via generator, following the same naming convention used in controllers and jobs. (Pull Request)

  • Added assert_enqueued_emails and assert_no_enqueued_emails. (Pull Request)

  • Added config.action_mailer.deliver_later_queue_name configuration to set the mailer queue name. (Pull Request)

Active Record

Please refer to the Changelog for detailed changes.

Removals

  • Removed deprecated behavior allowing nested arrays to be passed as query values. (Pull Request)

  • Removed deprecated ActiveRecord::Tasks::DatabaseTasks#load_schema. This method was replaced by ActiveRecord::Tasks::DatabaseTasks#load_schema_for. (commit)

  • Removed deprecated serialized_attributes. (commit)

  • Removed deprecated automatic counter caches on has_many :through. (commit)

  • Removed deprecated sanitize_sql_hash_for_conditions. (commit)

  • Removed deprecated Reflection#source_macro. (commit)

  • Removed deprecated symbolized_base_class and symbolized_sti_name. (commit)

  • Removed deprecated ActiveRecord::Base.disable_implicit_join_references=. (commit)

  • Removed deprecated access to connection specification using a string accessor. (commit)

  • Removed deprecated support to preload instance-dependent associations. (commit)

  • Removed deprecated support for PostgreSQL ranges with exclusive lower bounds. (commit)

  • Removed deprecation when modifying a relation with cached Arel. This raises an ImmutableRelation error instead. (commit)

  • Removed ActiveRecord::Serialization::XmlSerializer from core. This feature has been extracted into the activemodel-serializers-xml gem. (Pull Request)

  • Removed support for the legacy mysql database adapter from core. It will live on in a separate gem for now, but most users should just use mysql2.

  • Removed support for the protected_attributes gem. (commit)

Deprecations

  • Deprecated passing a class as a value in a query. Users should pass strings instead. (Pull Request)

  • Deprecated returning false as a way to halt Active Record callback chains. The recommended way is to throw(:abort). (Pull Request)

  • Deprecated ActiveRecord::Base.errors_in_transactional_callbacks=. (commit)

  • Deprecated passing of start value to find_in_batches and find_each in favour of begin_at value. (Pull Request)

  • Deprecated Relation#uniq use Relation#distinct instead. (commit)

  • Deprecated the PostgreSQL :point type in favor of a new one which will return Point objects instead of an Array (Pull Request)

  • Deprecated force association reload by passing a truthy argument to association method. (Pull Request)

  • Deprecated the keys for association restrict_dependent_destroy errors in favor of new key names. (Pull Request)

  • Synchronize behavior of #tables. (Pull Request)

  • Deprecated SchemaCache#tables, SchemaCache#table_exists? and SchemaCache#clear_table_cache! in favor of their new data source counterparts. (Pull Request)

  • Deprecated connection.tables on the SQLite3 and MySQL adapters. (Pull Request)

  • Deprecated passing arguments to #tables - the #tables method of some adapters (mysql2, sqlite3) would return both tables and views while others (postgresql) just return tables. To make their behavior consistent, #tables will return only tables in the future. (Pull Request)

  • Deprecated table_exists? - The #table_exists? method would check both tables and views. To make their behavior consistent with #tables, #table_exists? will check only tables in the future. (Pull Request)

  • Deprecate sending the offset argument to find_nth. Please use the offset method on relation instead. (Pull Request)

Notable changes

  • Added a foreign_key option to references while creating the table. (commit)

  • New attributes API. (commit)

  • Added :enum_prefix/:enum_suffix option to enum definition. (Pull Request)

  • Added #cache_key to ActiveRecord::Relation. (Pull Request)

  • Added ActiveRecord::Relation#outer_joins. (Pull Request)

  • Require belongs_to by default. (Pull Request) - Deprecate required option in favor of optional for belongs_to

  • Changed the default null value for timestamps to false. (commit)

  • Added ActiveRecord::SecureToken in order to encapsulate generation of unique tokens for attributes in a model using SecureRandom. (Pull Request)

  • Added :if_exists option for drop_table. (Pull Request)

  • Added ActiveRecord::Base#accessed_fields, which can be used to quickly discover which fields were read from a model when you are looking to only select the data you need from the database. (commit)

  • Added the #or method on ActiveRecord::Relation, allowing use of the OR operator to combine WHERE or HAVING clauses. (commit)

  • Added :time option added for #touch. (Pull Request)

  • Added ActiveRecord::Base.suppress to prevent the receiver from being saved during the given block. (Pull Request)

  • belongs_to will now trigger a validation error by default if the association is not present. You can turn this off on a per-association basis with optional: true. (Pull Request)

  • Added config.active_record.dump_schemas to configure the behavior of db:structure:dump. (Pull Request)

  • Added config.active_record.warn_on_records_fetched_greater_than option. (Pull Request)

  • Added a native JSON data type support in MySQL. (Pull Request)

  • Added support for dropping indexes concurrently in PostgreSQL. (Pull Request)

  • Added #views and #view_exists? methods on connection adapters. (Pull Request)

  • Added ActiveRecord::Base.ignored_columns to make some columns invisible from Active Record. (Pull Request)

  • Added connection.data_sources and connection.data_source_exists?. These methods determine what relations can be used to back Active Record models (usually tables and views). (Pull Request)

  • Allow fixtures files to set the model class in the YAML file itself. (Pull Request)

  • Added ability to default to uuid as primary key when generating database migrations. (Pull Request)

  • Added ActiveRecord::Relation#left_joins and ActiveRecord::Relation#left_outer_joins. (Pull Request)

  • Added after_{create,update,delete}_commit callbacks. (Pull Request)

  • Version the API presented to migration classes, so we can change parameter defaults without breaking existing migrations, or forcing them to be rewritten through a deprecation cycle. (Pull Request)

  • ApplicationRecord is a new superclass for all app models, analogous to app controllers subclassing ApplicationController instead of ActionController::Base. This gives apps a single spot to configure app-wide model behavior. (Pull Request)

Active Model

Please refer to the Changelog for detailed changes.

Removals

Deprecations

  • Deprecated returning false as a way to halt Active Model and ActiveModel::Validations callback chains. The recommended way is to throw(:abort). (Pull Request)

  • Deprecated ActiveModel::Errors#get, ActiveModel::Errors#set and ActiveModel::Errors#[]= methods that have inconsistent behavior. (Pull Request)

  • Deprecated the :tokenizer option for validates_length_of, in favor of plain Ruby. (Pull Request)

  • Deprecated ActiveModel::Errors#add_on_empty and ActiveModel::Errors#add_on_blank with no replacement. (Pull Request)

Notable changes

  • Added ActiveModel::Errors#details to determine what validator has failed. (Pull Request)

  • Extracted ActiveRecord::AttributeAssignment to ActiveModel::AttributeAssignment allowing to use it for any object as an includable module. (Pull Request)

  • Added ActiveModel::Dirty#[attr_name]_previously_changed? and ActiveModel::Dirty#[attr_name]_previous_change to improve access to recorded changes after the model has been saved. (Pull Request)

  • Validate multiple contexts on valid? and invalid? at once. (Pull Request)

Active Job

Please refer to the Changelog for detailed changes.

Notable changes

  • ActiveJob::Base.deserialize delegates to the job class. this allows jobs to attach arbitrary metadata when they get serialized and read it back when they get performed. (Pull Request)

  • A generated job now inherits from app/jobs/application_job.rb by default. (Pull Request)

  • Allow DelayedJob, Sidekiq, qu, and que to report the job id back to ActiveJob::Base as provider_job_id. (Pull Request, Pull Request)

  • Implement a simple AsyncJob processor and associated AsyncAdapter that queue jobs to a concurrent-ruby thread pool. (Pull Request)

Active Support

Please refer to the Changelog for detailed changes.

Removals

  • Removed deprecated ActiveSupport::JSON::Encoding::CircularReferenceError. (commit)

  • Removed deprecated methods ActiveSupport::JSON::Encoding.encode_big_decimal_as_string= and ActiveSupport::JSON::Encoding.encode_big_decimal_as_string. (commit)

  • Removed deprecated ActiveSupport::SafeBuffer#prepend. (commit)

  • Removed deprecated methods from Kernel. silence_stderr, silence_stream, capture and quietly. (commit)

  • Removed deprecated active_support/core_ext/big_decimal/yaml_conversions file. (commit)

  • Removed deprecated methods ActiveSupport::Cache::Store.instrument and ActiveSupport::Cache::Store.instrument=. (commit)

  • Removed deprecated Class#superclass_delegating_accessor. Use Class#class_attribute instead. (Pull Request)

  • Removed deprecated ThreadSafe::Cache. Use Concurrent::Map instead. (Pull Request)

Deprecations

  • Deprecated MissingSourceFile in favor of LoadError. (commit)

  • Deprecated alias_method_chain in favour of Module#prepend introduced in Ruby 2.0. (Pull Request)

  • Deprecated ActiveSupport::Concurrency::Latch in favor of Concurrent::CountDownLatch from concurrent-ruby. (Pull Request)

  • Deprecated :prefix option of number_to_human_size with no replacement. (Pull Request)

  • Deprecated Module#qualified_const_ in favour of the builtin Module#const_ methods. (Pull Request)

  • Deprecated passing string to define callback. (Pull Request)

  • Deprecated ActiveSupport::Cache::Store#namespaced_key, ActiveSupport::Cache::MemCachedStore#escape_key, and ActiveSupport::Cache::FileStore#key_file_path. Use normalize_key instead.

    Deprecated ActiveSupport::Cache::LocaleCache#set_cache_value in favor of write_cache_value. (Pull Request)

Notable changes

  • Added #verified and #valid_message? methods to ActiveSupport::MessageVerifier. (Pull Request)

  • Changed the way in which callback chains can be halted. The preferred method to halt a callback chain from now on is to explicitly throw(:abort). (Pull Request)

  • New config option config.active_support.halt_callback_chains_on_return_false to specify whether ActiveRecord, ActiveModel and ActiveModel::Validations callback chains can be halted by returning false in a 'before' callback. (Pull Request)

  • Changed the default test order from :sorted to :random. (commit)

  • Added #on_weekend?, #next_weekday, #prev_weekday methods to Date, Time, and DateTime. (Pull Request)

  • Added same_time option to #next_week and #prev_week for Date, Time, and DateTime. (Pull Request)

  • Added #prev_day and #next_day counterparts to #yesterday and #tomorrow for Date, Time, and DateTime. (Pull Request)

  • Added SecureRandom.base58 for generation of random base58 strings. (commit)

  • Added file_fixture to ActiveSupport::TestCase. It provides a simple mechanism to access sample files in your test cases. (Pull Request)

  • Added #without on Enumerable and Array to return a copy of an enumerable without the specified elements. (Pull Request)

  • Added ActiveSupport::ArrayInquirer and Array#inquiry. (Pull Request)

  • Added ActiveSupport::TimeZone#strptime to allow parsing times as if from a given timezone. (commit)

  • Added Integer#positive? and Integer#negative? query methods in the vein of Fixnum#zero?. (commit)

  • Added a bang version to ActiveSupport::OrderedOptions get methods which will raise an KeyError if the value is .blank?. (Pull Request)

  • Added Time.days_in_year to return the number of days in the given year, or the current year if no argument is provided. (commit)

  • Added an evented file watcher to asynchronously detect changes in the application source code, routes, locales, etc. (Pull Request)

  • Added thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread. (Pull Request)

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.