1 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.
2 Major Features
2.1 Action Cable
ToDo...
2.2 Rails API
ToDo...
2.3 Active Record attributes API
ToDo...
2.4 Test Runner
ToDo...
3 Railties
Please refer to the Changelog for detailed changes.
3.1 Removals
Removed debugger support, use byebug instead.
debuggeris not supported by Ruby 2.2. (commit)Removed deprecated
test:allandtest:all:dbtasks. (commit)Removed deprecated
Rails::Rack::LogTailer. (commit)Removed deprecated
RAILS_CACHEconstant. (commit)Removed deprecated
serve_static_assetsconfiguration. (commit)Removed the documentation tasks
doc:app,doc:rails, anddoc:guides. (commit)Removed
Rack::ContentLengthmiddleware from the default stack. (Commit)
3.2 Deprecations
Deprecated
config.static_cache_controlin favor ofconfig.public_file_server.headers. (Pull Request)Deprecated
config.serve_static_filesin favor ofconfig.public_file_server.enabled. (Pull Request)Deprecated the tasks in the
railstask namespace in favor of theappnamespace. (e.g.rails:updateandrails:templatetasks is renamed toapp:updateandapp:template.) (Pull Request)
3.3 Notable changes
Added Rails test runner
bin/rails test. (Pull Request)Newly generated applications and plugins get a
README.mdin Markdown. (commit, Pull Request)Added
bin/rails restarttask to restart your Rails app by touchingtmp/restart.txt. (Pull Request)Added
bin/rails initializerstask to print out all defined initializers in the order they are invoked by Rails. (Pull Request)Added
bin/rails dev:cacheto enable or disable caching in development mode. (Pull Request)Added
bin/updatescript to update the development environment automatically. (Pull Request)Proxy Rake tasks through
bin/rails. (Pull Request, Pull Request)New applications are generated with the evented file system monitor enabled on Linux and Mac OS X. The feature can be opted out by passing
--skip-listento the generator. (commit, commit)Generate applications with an option to log to STDOUT in production using the environment variable
RAILS_LOG_TO_STDOUT. (Pull Request)Enable HSTS with IncludeSudomains header for new applications. (Pull Request)
The application generator writes a new file
config/spring.rb, which tells Spring to watch additional common files. (commit)
4 Action Pack
Please refer to the Changelog for detailed changes.
4.1 Removals
Removed
ActionDispatch::Request::Utils.deep_munge. (commit)Removed
ActionController::HideActions. (Pull Request)Removed
respond_toandrespond_withplaceholder 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_pathoption on*_pathhelpers. (commit)Removed deprecated
NamedRouteCollection#helpers. (commit)Removed deprecated support to define routes with
:tooption 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_routein controller tests. (commit)Removed
assignsandassert_template. Both methods have been extracted into the rails-controller-testing gem. (Pull Request)
4.2 Deprecations
Deprecated all
*_filtercallbacks in favor of*_actioncallbacks. (Pull Request)Deprecated
*_via_redirectintegration test methods. Usefollow_redirect!manually after the request call for the same behavior. (Pull Request)Deprecated
AbstractController#skip_action_callbackin favor of individual skip_callback methods. (Pull Request)Deprecated
:nothingoption forrendermethod. (Pull Request)Deprecated passing first parameter as
Hashand default status code forheadmethod. (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 :backin favor ofredirect_back, which accepts a requiredfallback_locationargument, thus eliminating the possibility of aRedirectBackError. (Pull Request)
4.3 Notable changes
Added
ActionController::Rendererto render arbitrary templates outside controller actions. (Pull Request)Migrating to keyword arguments syntax in
ActionController::TestCaseandActionDispatch::IntegrationHTTP request methods. (Pull Request)Added
http_cache_foreverto 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_contentinstead 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::APIis added as a replacement ofActionController::Basefor this kind of applications. (Pull Request)Make
ActionController::Parametersno longer inherits fromHashWithIndifferentAccess. (Pull Request)Make it easier to opt in to
config.force_sslandconfig.ssl_optionsby 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_forgeryprepend default tofalse. (commit)ActionController::TestCasewill be moved to its own gem in Rails 5.1. UseActionDispatch::IntegrationTestinstead. (commit)Rails will only generate "weak", instead of strong ETags. (Pull Request)
Controller actions without an explicit
rendercall and with no corresponding templates will renderhead :no_contentimplicitly instead of raising an error. (Pull Request 1, 2)Added an option for per-form CSRF tokens. (Pull Request)
Added request encoding and response parsing to integration tests. (Pull Request)
Update default rendering policies when the controller action did not explicitly indicate a response. (Pull Request)
5 Action View
Please refer to the Changelog for detailed changes.
5.1 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_formatoption fortranslatehelper since it's no longer supported by I18n. (Pull Request)
5.2 Notable Changes
Changed the default template handler from
ERBtoRaw. (commit)Collection rendering can cache and fetches multiple partials. (Pull Request, commit)
Added wildcard matching to explicit dependencies. (Pull Request)
Make
disable_withthe default behavior for submit tags. Disables the button on submit to prevent double submits. (Pull Request)Collection rendering can cache and fetch multiple partials at once. (Pull Request)
6 Action Mailer
Please refer to the Changelog for detailed changes.
6.1 Removals
Removed deprecated
*_pathhelpers in email views. (commit)Removed deprecated
deliveranddeliver!methods. (commit)
6.2 Notable changes
Template lookup now respects default locale and I18n fallbacks. (commit)
Added
_mailersuffix to mailers created via generator, following the same naming convention used in controllers and jobs. (Pull Request)Added
assert_enqueued_emailsandassert_no_enqueued_emails. (Pull Request)Added
config.action_mailer.deliver_later_queue_nameconfiguration to set the mailer queue name. (Pull Request)Added support for fragment caching in Action Mailer views. Added new config option
config.action_mailer.perform_cachingto determine whether your templates should perform caching or not. (Pull Request)
7 Active Record
Please refer to the Changelog for detailed changes.
7.1 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 byActiveRecord::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_classandsymbolized_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
ImmutableRelationerror instead. (commit)Removed
ActiveRecord::Serialization::XmlSerializerfrom core. This feature has been extracted into the activemodel-serializers-xml gem. (Pull Request)Removed support for the legacy
mysqldatabase adapter from core. It will live on in a separate gem for now, but most users should just usemysql2.Removed support for the
protected_attributesgem. (commit)Removed support for PostgreSQL versions below 9.1. (Pull Request)
7.2 Deprecations
Deprecated passing a class as a value in a query. Users should pass strings instead. (Pull Request)
Deprecated returning
falseas a way to halt Active Record callback chains. The recommended way is tothrow(:abort). (Pull Request)Deprecated
ActiveRecord::Base.errors_in_transactional_callbacks=. (commit)Deprecated
Relation#uniquseRelation#distinctinstead. (commit)Deprecated the PostgreSQL
:pointtype in favor of a new one which will returnPointobjects instead of anArray(Pull Request)Deprecated force association reload by passing a truthy argument to association method. (Pull Request)
Deprecated the keys for association
restrict_dependent_destroyerrors in favor of new key names. (Pull Request)Synchronize behavior of
#tables. (Pull Request)Deprecated
SchemaCache#tables,SchemaCache#table_exists?andSchemaCache#clear_table_cache!in favor of their new data source counterparts. (Pull Request)Deprecated
connection.tableson the SQLite3 and MySQL adapters. (Pull Request)Deprecated passing arguments to
#tables- the#tablesmethod of some adapters (mysql2, sqlite3) would return both tables and views while others (postgresql) just return tables. To make their behavior consistent,#tableswill 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
offsetargument tofind_nth. Please use theoffsetmethod on relation instead. (Pull Request)Deprecated
{insert|update|delete}_sqlinDatabaseStatements. Use the{insert|update|delete}public methods instead. (Pull Request)
7.3 Notable changes
Added a
foreign_keyoption toreferenceswhile creating the table. (commit)New attributes API. (commit)
Added
:enum_prefix/:enum_suffixoption toenumdefinition. (Pull Request)Added
#cache_keytoActiveRecord::Relation. (Pull Request)Require
belongs_toby default. (Pull Request) - Deprecaterequiredoption in favor ofoptionalforbelongs_toChanged the default
nullvalue fortimestampstofalse. (commit)Added
ActiveRecord::SecureTokenin order to encapsulate generation of unique tokens for attributes in a model usingSecureRandom. (Pull Request)Added
:if_existsoption fordrop_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
#ormethod onActiveRecord::Relation, allowing use of the OR operator to combine WHERE or HAVING clauses. (commit)Added
:timeoption added for#touch. (Pull Request)Added
ActiveRecord::Base.suppressto prevent the receiver from being saved during the given block. (Pull Request)belongs_towill now trigger a validation error by default if the association is not present. You can turn this off on a per-association basis withoptional: true. (Pull Request)Added
config.active_record.dump_schemasto configure the behavior ofdb:structure:dump. (Pull Request)Added
config.active_record.warn_on_records_fetched_greater_thanoption. (Pull Request)Added a native JSON data type support in MySQL. (Pull Request)
Added support for dropping indexes concurrently in PostgreSQL. (Pull Request)
Added
#viewsand#view_exists?methods on connection adapters. (Pull Request)Added
ActiveRecord::Base.ignored_columnsto make some columns invisible from Active Record. (Pull Request)Added
connection.data_sourcesandconnection.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
uuidas primary key when generating database migrations. (Pull Request)Added
ActiveRecord::Relation#left_joinsandActiveRecord::Relation#left_outer_joins. (Pull Request)Added
after_{create,update,delete}_commitcallbacks. (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)
ApplicationRecordis a new superclass for all app models, analogous to app controllers subclassingApplicationControllerinstead ofActionController::Base. This gives apps a single spot to configure app-wide model behavior. (Pull Request)Added ActiveRecord
#second_to_lastand#third_to_lastmethods. (Pull Request)Added ability to annotate database objects (tables, columns, indexes) with comments stored in database metadata for PostgreSQL & MySQL. (Pull Request)
8 Active Model
Please refer to the Changelog for detailed changes.
8.1 Removals
Removed deprecated
ActiveModel::Dirty#reset_#{attribute}andActiveModel::Dirty#reset_changes. (Pull Request)Removed XML serialization. This feature has been extracted into the activemodel-serializers-xml gem. (Pull Request)
8.2 Deprecations
Deprecated returning
falseas a way to halt Active Model andActiveModel::Validationscallback chains. The recommended way is tothrow(:abort). (Pull Request)Deprecated
ActiveModel::Errors#get,ActiveModel::Errors#setandActiveModel::Errors#[]=methods that have inconsistent behavior. (Pull Request)Deprecated the
:tokenizeroption forvalidates_length_of, in favor of plain Ruby. (Pull Request)Deprecated
ActiveModel::Errors#add_on_emptyandActiveModel::Errors#add_on_blankwith no replacement. (Pull Request)
8.3 Notable changes
Added
ActiveModel::Errors#detailsto determine what validator has failed. (Pull Request)Extracted
ActiveRecord::AttributeAssignmenttoActiveModel::AttributeAssignmentallowing to use it for any object as an includable module. (Pull Request)Added
ActiveModel::Dirty#[attr_name]_previously_changed?andActiveModel::Dirty#[attr_name]_previous_changeto improve access to recorded changes after the model has been saved. (Pull Request)Validate multiple contexts on
valid?andinvalid?at once. (Pull Request)
9 Active Job
Please refer to the Changelog for detailed changes.
9.1 Notable changes
ActiveJob::Base.deserializedelegates 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.rbby default. (Pull Request)Allow
DelayedJob,Sidekiq,qu,que, andqueue_classicto report the job id back toActiveJob::Baseasprovider_job_id. (Pull Request, Pull Request, commit)Implement a simple
AsyncJobprocessor and associatedAsyncAdapterthat queue jobs to aconcurrent-rubythread pool. (Pull Request)Change the default adapter from inline to async. It's a better default as tests will then not mistakenly come to rely on behavior happening synchronously. (commit)
10 Active Support
Please refer to the Changelog for detailed changes.
10.1 Removals
Removed deprecated
ActiveSupport::JSON::Encoding::CircularReferenceError. (commit)Removed deprecated methods
ActiveSupport::JSON::Encoding.encode_big_decimal_as_string=andActiveSupport::JSON::Encoding.encode_big_decimal_as_string. (commit)Removed deprecated
ActiveSupport::SafeBuffer#prepend. (commit)Removed deprecated methods from
Kernel.silence_stderr,silence_stream,captureandquietly. (commit)Removed deprecated
active_support/core_ext/big_decimal/yaml_conversionsfile. (commit)Removed deprecated methods
ActiveSupport::Cache::Store.instrumentandActiveSupport::Cache::Store.instrument=. (commit)Removed deprecated
Class#superclass_delegating_accessor. UseClass#class_attributeinstead. (Pull Request)Removed deprecated
ThreadSafe::Cache. UseConcurrent::Mapinstead. (Pull Request)
10.2 Deprecations
Deprecated
MissingSourceFilein favor ofLoadError. (commit)Deprecated
alias_method_chainin favour ofModule#prependintroduced in Ruby 2.0. (Pull Request)Deprecated
ActiveSupport::Concurrency::Latchin favor ofConcurrent::CountDownLatchfrom concurrent-ruby. (Pull Request)Deprecated
:prefixoption ofnumber_to_human_sizewith no replacement. (Pull Request)Deprecated
Module#qualified_const_in favour of the builtinModule#const_methods. (Pull Request)Deprecated passing string to define callback. (Pull Request)
-
Deprecated
ActiveSupport::Cache::Store#namespaced_key,ActiveSupport::Cache::MemCachedStore#escape_key, andActiveSupport::Cache::FileStore#key_file_path. Usenormalize_keyinstead.Deprecated
ActiveSupport::Cache::LocaleCache#set_cache_valuein favor ofwrite_cache_value. (Pull Request) Deprecated passing arguments to
assert_nothing_raised. (Pull Request)Deprecated
Module.local_constantsin favor ofModule.constants(false). (Pull Request)
10.3 Notable changes
Added
#verifiedand#valid_message?methods toActiveSupport::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_falseto specify whether ActiveRecord, ActiveModel and ActiveModel::Validations callback chains can be halted by returningfalsein a 'before' callback. (Pull Request)Changed the default test order from
:sortedto:random. (commit)Added
#on_weekend?,#on_weekday?,#next_weekday,#prev_weekdaymethods toDate,Time, andDateTime. (Pull Request)Added
same_timeoption to#next_weekand#prev_weekforDate,Time, andDateTime. (Pull Request)Added
#prev_dayand#next_daycounterparts to#yesterdayand#tomorrowforDate,Time, andDateTime. (Pull Request)Added
SecureRandom.base58for generation of random base58 strings. (commit)Added
file_fixturetoActiveSupport::TestCase. It provides a simple mechanism to access sample files in your test cases. (Pull Request)Added
#withoutonEnumerableandArrayto return a copy of an enumerable without the specified elements. (Pull Request)Added
ActiveSupport::ArrayInquirerandArray#inquiry. (Pull Request)Added
ActiveSupport::TimeZone#strptimeto allow parsing times as if from a given timezone. (commit)Added
Integer#positive?andInteger#negative?query methods in the vein ofFixnum#zero?. (commit)Added a bang version to
ActiveSupport::OrderedOptionsget methods which will raise anKeyErrorif the value is.blank?. (Pull Request)Added
Time.days_in_yearto 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)
Added
Array#second_to_lastandArray#third_to_lastmethods. (Pull Request)Added
#on_weekday?method toDate,Time, andDateTime. (Pull Request)Publish
ActiveSupport::ExecutorandActiveSupport::ReloaderAPIs to allow components and libraries to manage, and participate in, the execution of application code, and the application reloading process. (Pull Request)ActiveSupport::Durationnow supports ISO8601 formatting and parsing. (Pull Request)
11 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.
Feedback
You're encouraged to help improve the quality of this guide.
Please contribute if you see any typos or factual errors. To get started, you can read our documentation contributions section.
You may also find incomplete content, or stuff that is not up to date. Please do add any missing documentation for master. Make sure to check Edge Guides first to verify if the issues are already fixed or not on the master branch. Check the Ruby on Rails Guides Guidelines for style and conventions.
If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.
And last but not least, any kind of discussion regarding Ruby on Rails documentation is very welcome in the rubyonrails-docs mailing list.