CINXE.COM

Ruby on Rails 4.0 Release Notes — Ruby on Rails Guides

<!doctype html> <html dir="ltr" lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Ruby on Rails 4.0 Release Notes — Ruby on Rails Guides</title> <link rel="stylesheet" type="text/css" href="stylesheets/style-6fc5bf25e695f363fd1dd3d9dbb2f997.css" data-turbo-track="reload"> <link rel="stylesheet" type="text/css" href="stylesheets/print-a87ee66d50ce96bb83ac082f1249fe3e.css" media="print"> <link rel="stylesheet" type="text/css" href="stylesheets/highlight-2794201d063bd2e4dbd0f0874c2a3f6f.css" data-turbo-track="reload"> <link rel="icon" href="images/favicon.ico" sizes="any"> <link rel="apple-touch-icon" href="images/icon.png"> <link rel="canonical" href="https://guides.rubyonrails.org/4_0_release_notes.html"> <script src="javascripts/@hotwired--turbo-764f59c7edbeb902a9068c0340dd274e.js" data-turbo-track="reload"></script> <script src="javascripts/clipboard-8b7aed6f069f0cf58eeae353cd2f898b.js" data-turbo-track="reload"></script> <script src="javascripts/guides-751b87e159daf790ddf7e8e88ad8465a.js" data-turbo-track="reload"></script> <meta property="og:title" content="Ruby on Rails 4.0 Release Notes — Ruby on Rails Guides" /> <meta name="description" content="Ruby on Rails 4.0 Release NotesHighlights in Rails 4.0: Ruby 2.0 preferred; 1.9.3+ required Strong Parameters Turbolinks Russian Doll Caching 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." /> <meta property="og:description" content="Ruby on Rails 4.0 Release NotesHighlights in Rails 4.0: Ruby 2.0 preferred; 1.9.3+ required Strong Parameters Turbolinks Russian Doll Caching 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." /> <meta property="og:locale" content="en_US" /> <meta property="og:site_name" content="Ruby on Rails Guides" /> <meta property="og:image" content="https://avatars.githubusercontent.com/u/4223" /> <meta property="og:type" content="website" /> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@100..900&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Heebo:wght@100..900&family=Noto+Sans+Arabic:wght@100..900&display=swap" rel="stylesheet"> <meta name="theme-color" content="#C81418"> </head> <body dir="ltr" class="guide no-js"> <script> document.body.classList.remove('no-js') </script> <a id="main-skip-link" href="#main" class="skip-link" data-turbo="false"> Skip to main content </a> <div id="mobile-navigation-bar"> <div class="wrapper"> <strong class="more-info-label">More at <a href="https://rubyonrails.org/">rubyonrails.org:</a> </strong> <button type="button" class="js-only red-button more-info-button" id="more-info" aria-controls="more-info-links" aria-expanded="false"> More Ruby on Rails </button> <ul id="more-info-links" class="more-info-links hidden"> <li class="more-info"><a href="https://rubyonrails.org/blog">Blog</a></li> <li class="more-info"><a href="https://guides.rubyonrails.org/">Guides</a></li> <li class="more-info"><a href="https://api.rubyonrails.org/">API</a></li> <li class="more-info"><a href="https://discuss.rubyonrails.org/">Forum</a></li> <li class="more-info"><a href="https://github.com/rails/rails">Contribute on GitHub</a></li> </ul> </div> </div> <header id="page-header"> <div class="wrapper clearfix"> <nav id="feature-nav"> <div class="header-logo"> <a href="index.html" title="Guides home for v8.0.1 Guides">Guides</a> <span id="version-switcher" class="js-only"> <label for="version-switcher-select">Version: <span class="visibly-hidden">pick from the list to go to that Rails version's guides</span></label> <select id="version-switcher-select" class="guides-version"> <option value="https://edgeguides.rubyonrails.org/">Edge</option> <option value="https://guides.rubyonrails.org/v8.0/4_0_release_notes.html" selected>8.0</option> <option value="https://guides.rubyonrails.org/v7.2/4_0_release_notes.html">7.2</option> <option value="https://guides.rubyonrails.org/v7.1/4_0_release_notes.html">7.1</option> <option value="https://guides.rubyonrails.org/v7.0/4_0_release_notes.html">7.0</option> <option value="https://guides.rubyonrails.org/v6.1/4_0_release_notes.html">6.1</option> <option value="https://guides.rubyonrails.org/v6.0/4_0_release_notes.html">6.0</option> <option value="https://guides.rubyonrails.org/v5.2/4_0_release_notes.html">5.2</option> <option value="https://guides.rubyonrails.org/v5.1/4_0_release_notes.html">5.1</option> <option value="https://guides.rubyonrails.org/v5.0/4_0_release_notes.html">5.0</option> <option value="https://guides.rubyonrails.org/v4.2/4_0_release_notes.html">4.2</option> <option value="https://guides.rubyonrails.org/v4.1/4_0_release_notes.html">4.1</option> <option value="https://guides.rubyonrails.org/v4.0/4_0_release_notes.html">4.0</option> <option value="https://guides.rubyonrails.org/v3.2/4_0_release_notes.html">3.2</option> <option value="https://guides.rubyonrails.org/v3.1/4_0_release_notes.html">3.1</option> <option value="https://guides.rubyonrails.org/v3.0/4_0_release_notes.html">3.0</option> <option value="https://guides.rubyonrails.org/v2.3/4_0_release_notes.html">2.3</option> </select> </span> </div> <ul class="nav"> <li><a class="nav-item" id="home_nav" href="https://rubyonrails.org/">Home</a></li> <li class="guides-index guides-index-large"> <a href="index.html" id="guides-menu-button" data-aria-controls="guides" data-aria-expanded="false" class="guides-index-item nav-item">Guides Index</a> <div id="guides" class="clearfix" style="display: none;"> <hr /> <dl class="guides-section-container"> <div class="guides-section"> <dt>Start Here</dt> <dd><a href="getting_started.html">Getting Started with Rails</a></dd> <dd><a href="install_ruby_on_rails.html">Install Ruby on Rails</a></dd> </div> <div class="guides-section"> <dt>Models</dt> <dd><a href="active_record_basics.html">Active Record Basics</a></dd> <dd><a href="active_record_migrations.html">Active Record Migrations</a></dd> <dd><a href="active_record_validations.html">Active Record Validations</a></dd> <dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd> <dd><a href="association_basics.html">Active Record Associations</a></dd> <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd> <dd><a href="active_model_basics.html">Active Model Basics</a></dd> </div> <div class="guides-section"> <dt>Views</dt> <dd><a href="action_view_overview.html">Action View Overview</a></dd> <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd> <dd><a href="action_view_helpers.html">Action View Helpers</a></dd> <dd><a href="form_helpers.html">Action View Form Helpers</a></dd> </div> <div class="guides-section"> <dt>Controllers</dt> <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd> <dd><a href="action_controller_advanced_topics.html">Action Controller Advanced Topics</a></dd> <dd><a href="routing.html">Rails Routing from the Outside In</a></dd> </div> <div class="guides-section"> <dt>Other Components</dt> <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd> <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd> <dd><a href="action_mailbox_basics.html">Action Mailbox Basics</a></dd> <dd><a href="action_text_overview.html">Action Text Overview</a></dd> <dd><a href="active_job_basics.html">Active Job Basics</a></dd> <dd><a href="active_storage_overview.html">Active Storage Overview</a></dd> <dd><a href="action_cable_overview.html">Action Cable Overview</a></dd> </div> <div class="guides-section"> <dt>Digging Deeper</dt> <dd><a href="i18n.html">Rails Internationalization (I18n) API</a></dd> <dd><a href="testing.html">Testing Rails Applications</a></dd> <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd> <dd><a href="configuring.html">Configuring Rails Applications</a></dd> <dd><a href="command_line.html">The Rails Command Line</a></dd> <dd><a href="asset_pipeline.html">The Asset Pipeline</a></dd> <dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd> <dd><a href="autoloading_and_reloading_constants.html">Autoloading and Reloading</a></dd> <dd><a href="api_app.html">Using Rails for API-only Applications</a></dd> </div> <div class="guides-section"> <dt>Going to Production</dt> <dd><a href="tuning_performance_for_deployment.html">Tuning Performance for Deployment</a></dd> <dd><a href="caching_with_rails.html">Caching with Rails: An Overview</a></dd> <dd><a href="security.html">Securing Rails Applications</a></dd> <dd><a href="error_reporting.html">Error Reporting in Rails Applications</a></dd> </div> <div class="guides-section"> <dt>Advanced Active Record</dt> <dd><a href="active_record_multiple_databases.html">Multiple Databases</a></dd> <dd><a href="active_record_composite_primary_keys.html">Composite Primary Keys</a></dd> </div> <div class="guides-section"> <dt>Extending Rails</dt> <dd><a href="rails_on_rack.html">Rails on Rack</a></dd> <dd><a href="generators.html">Creating and Customizing Rails Generators &amp; Templates</a></dd> </div> <div class="guides-section"> <dt>Contributing</dt> <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd> <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd> <dd><a href="ruby_on_rails_guides_guidelines.html">Guides Guidelines</a></dd> <dd><a href="development_dependencies_install.html">Installing Rails Core Development Dependencies</a></dd> </div> <div class="guides-section"> <dt>Policies</dt> <dd><a href="maintenance_policy.html">Maintenance Policy</a></dd> </div> <div class="guides-section"> <dt>Release Notes</dt> <dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd> <dd><a href="8_0_release_notes.html">Version 8.0 - November 2024</a></dd> <dd><a href="7_2_release_notes.html">Version 7.2 - August 2024</a></dd> <dd><a href="7_1_release_notes.html">Version 7.1 - October 2023</a></dd> <dd><a href="7_0_release_notes.html">Version 7.0 - December 2021</a></dd> <dd><a href="6_1_release_notes.html">Version 6.1 - December 2020</a></dd> <dd><a href="6_0_release_notes.html">Version 6.0 - August 2019</a></dd> <dd><a href="5_2_release_notes.html">Version 5.2 - April 2018</a></dd> <dd><a href="5_1_release_notes.html">Version 5.1 - April 2017</a></dd> <dd><a href="5_0_release_notes.html">Version 5.0 - June 2016</a></dd> <dd><a href="4_2_release_notes.html">Version 4.2 - December 2014</a></dd> <dd><a href="4_1_release_notes.html">Version 4.1 - April 2014</a></dd> <dd><a href="4_0_release_notes.html">Version 4.0 - June 2013</a></dd> <dd><a href="3_2_release_notes.html">Version 3.2 - January 2012</a></dd> <dd><a href="3_1_release_notes.html">Version 3.1 - August 2011</a></dd> <dd><a href="3_0_release_notes.html">Version 3.0 - August 2010</a></dd> <dd><a href="2_3_release_notes.html">Version 2.3 - March 2009</a></dd> <dd><a href="2_2_release_notes.html">Version 2.2 - November 2008</a></dd> </div> </dl> </div> </li> <li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li> <li class="guides-index guides-index-small js-only"> <label for="guides-selector"> Navigate to a guide: </label> <select id="guides-selector" class="guides-index-item nav-item"> <option value="index.html">Guides Index</option> <optgroup label="Start Here"> <option value="getting_started.html">Getting Started with Rails</option> <option value="install_ruby_on_rails.html">Install Ruby on Rails</option> </optgroup> <optgroup label="Models"> <option value="active_record_basics.html">Active Record Basics</option> <option value="active_record_migrations.html">Active Record Migrations</option> <option value="active_record_validations.html">Active Record Validations</option> <option value="active_record_callbacks.html">Active Record Callbacks</option> <option value="association_basics.html">Active Record Associations</option> <option value="active_record_querying.html">Active Record Query Interface</option> <option value="active_model_basics.html">Active Model Basics</option> </optgroup> <optgroup label="Views"> <option value="action_view_overview.html">Action View Overview</option> <option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option> <option value="action_view_helpers.html">Action View Helpers</option> <option value="form_helpers.html">Action View Form Helpers</option> </optgroup> <optgroup label="Controllers"> <option value="action_controller_overview.html">Action Controller Overview</option> <option value="action_controller_advanced_topics.html">Action Controller Advanced Topics</option> <option value="routing.html">Rails Routing from the Outside In</option> </optgroup> <optgroup label="Other Components"> <option value="active_support_core_extensions.html">Active Support Core Extensions</option> <option value="action_mailer_basics.html">Action Mailer Basics</option> <option value="action_mailbox_basics.html">Action Mailbox Basics</option> <option value="action_text_overview.html">Action Text Overview</option> <option value="active_job_basics.html">Active Job Basics</option> <option value="active_storage_overview.html">Active Storage Overview</option> <option value="action_cable_overview.html">Action Cable Overview</option> </optgroup> <optgroup label="Digging Deeper"> <option value="i18n.html">Rails Internationalization (I18n) API</option> <option value="testing.html">Testing Rails Applications</option> <option value="debugging_rails_applications.html">Debugging Rails Applications</option> <option value="configuring.html">Configuring Rails Applications</option> <option value="command_line.html">The Rails Command Line</option> <option value="asset_pipeline.html">The Asset Pipeline</option> <option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option> <option value="autoloading_and_reloading_constants.html">Autoloading and Reloading</option> <option value="api_app.html">Using Rails for API-only Applications</option> </optgroup> <optgroup label="Going to Production"> <option value="tuning_performance_for_deployment.html">Tuning Performance for Deployment</option> <option value="caching_with_rails.html">Caching with Rails: An Overview</option> <option value="security.html">Securing Rails Applications</option> <option value="error_reporting.html">Error Reporting in Rails Applications</option> </optgroup> <optgroup label="Advanced Active Record"> <option value="active_record_multiple_databases.html">Multiple Databases</option> <option value="active_record_composite_primary_keys.html">Composite Primary Keys</option> </optgroup> <optgroup label="Extending Rails"> <option value="rails_on_rack.html">Rails on Rack</option> <option value="generators.html">Creating and Customizing Rails Generators &amp; Templates</option> </optgroup> <optgroup label="Contributing"> <option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option> <option value="api_documentation_guidelines.html">API Documentation Guidelines</option> <option value="ruby_on_rails_guides_guidelines.html">Guides Guidelines</option> <option value="development_dependencies_install.html">Installing Rails Core Development Dependencies</option> </optgroup> <optgroup label="Policies"> <option value="maintenance_policy.html">Maintenance Policy</option> </optgroup> <optgroup label="Release Notes"> <option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option> <option value="8_0_release_notes.html">Version 8.0 - November 2024</option> <option value="7_2_release_notes.html">Version 7.2 - August 2024</option> <option value="7_1_release_notes.html">Version 7.1 - October 2023</option> <option value="7_0_release_notes.html">Version 7.0 - December 2021</option> <option value="6_1_release_notes.html">Version 6.1 - December 2020</option> <option value="6_0_release_notes.html">Version 6.0 - August 2019</option> <option value="5_2_release_notes.html">Version 5.2 - April 2018</option> <option value="5_1_release_notes.html">Version 5.1 - April 2017</option> <option value="5_0_release_notes.html">Version 5.0 - June 2016</option> <option value="4_2_release_notes.html">Version 4.2 - December 2014</option> <option value="4_1_release_notes.html">Version 4.1 - April 2014</option> <option value="4_0_release_notes.html">Version 4.0 - June 2013</option> <option value="3_2_release_notes.html">Version 3.2 - January 2012</option> <option value="3_1_release_notes.html">Version 3.1 - August 2011</option> <option value="3_0_release_notes.html">Version 3.0 - August 2010</option> <option value="2_3_release_notes.html">Version 2.3 - March 2009</option> <option value="2_2_release_notes.html">Version 2.2 - November 2008</option> </optgroup> </select> </li> </ul> </nav> </div> </header> <hr class="hide" /> <main id="main"> <article> <header id="feature"> <div class="wrapper"> <h1>Ruby on Rails 4.0 Release Notes</h1><p>Highlights in Rails 4.0:</p> <ul> <li>Ruby 2.0 preferred; 1.9.3+ required</li> <li>Strong Parameters</li> <li>Turbolinks</li> <li>Russian Doll Caching</li> </ul> <p>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 <a href="https://github.com/rails/rails/commits/4-0-stable">list of commits</a> in the main Rails repository on GitHub.</p> <nav id="column-side" aria-label="Chapter" class="guide-index" data-turbo="false"> <a id="chapter-nav-skip-link" href="#article-body" class="skip-link"> Skip to article body </a> <h2 class="chapter"> <picture aria-hidden="true"> <!-- Using the `source` HTML tag to set the dark theme image --> <source srcset="images/icon_book-close-bookmark-1-wht.svg" media="(prefers-color-scheme: dark)" /> <img src="images/icon_book-close-bookmark-1.svg" alt="Chapter Icon" /> </picture> Chapters </h2> <ol class="chapters"> <li><a href="#upgrading-to-rails-4-0">Upgrading to Rails 4.0</a></li> <li><a href="#creating-a-rails-4-0-application">Creating a Rails 4.0 application</a> <ul> <li><a href="#vendoring-gems">Vendoring Gems</a></li> <li><a href="#living-on-the-edge">Living on the Edge</a></li> </ul></li> <li><a href="#major-features">Major Features</a> <ul> <li><a href="#upgrade">Upgrade</a></li> <li><a href="#actionpack">ActionPack</a></li> <li><a href="#general">General</a></li> <li><a href="#security">Security</a></li> </ul></li> <li><a href="#extraction-of-features-to-gems">Extraction of features to gems</a></li> <li><a href="#documentation">Documentation</a></li> <li><a href="#railties">Railties</a> <ul> <li><a href="#railties-notable-changes">Notable changes</a></li> <li><a href="#railties-deprecations">Deprecations</a></li> </ul></li> <li><a href="#action-mailer">Action Mailer</a> <ul> <li><a href="#action-mailer-notable-changes">Notable changes</a></li> <li><a href="#action-mailer-deprecations">Deprecations</a></li> </ul></li> <li><a href="#active-model">Active Model</a> <ul> <li><a href="#active-model-notable-changes">Notable changes</a></li> <li><a href="#active-model-deprecations">Deprecations</a></li> </ul></li> <li><a href="#active-support">Active Support</a> <ul> <li><a href="#active-support-notable-changes">Notable changes</a></li> <li><a href="#active-support-deprecations">Deprecations</a></li> </ul></li> <li><a href="#action-pack">Action Pack</a> <ul> <li><a href="#action-pack-notable-changes">Notable changes</a></li> <li><a href="#action-pack-deprecations">Deprecations</a></li> </ul></li> <li><a href="#active-record">Active Record</a> <ul> <li><a href="#active-record-notable-changes">Notable changes</a></li> <li><a href="#active-record-deprecations">Deprecations</a></li> </ul></li> <li><a href="#credits">Credits</a></li> </ol> </nav> </div> </header> <div class="wrapper"> <div id="column-main"> <section id="article-body"> <h2 id="upgrading-to-rails-4-0"><a class="anchorlink" href="#upgrading-to-rails-4-0" data-turbo="false"><span>1</span> Upgrading to Rails 4.0</a></h2><p>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 3.2 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 4.0. A list of things to watch out for when upgrading is available in the <a href="upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0">Upgrading Ruby on Rails</a> guide.</p><h2 id="creating-a-rails-4-0-application"><a class="anchorlink" href="#creating-a-rails-4-0-application" data-turbo="false"><span>2</span> Creating a Rails 4.0 application</a></h2><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">#</span><span class="w"> </span>You should have the <span class="s1">'rails'</span> RubyGem installed <span class="gp">$</span><span class="w"> </span><span class="nb">rails </span>new myapp <span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>myapp </code></pre> <button class="clipboard-button" data-clipboard-text="rails new myapp cd myapp ">Copy</button> </div> <h3 id="vendoring-gems"><a class="anchorlink" href="#vendoring-gems" data-turbo="false"><span>2.1</span> Vendoring Gems</a></h3><p>Rails now uses a <code>Gemfile</code> in the application root to determine the gems you require for your application to start. This <code>Gemfile</code> is processed by the <a href="https://github.com/carlhuda/bundler">Bundler</a> gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.</p><p>More information: <a href="https://bundler.io">Bundler homepage</a></p><h3 id="living-on-the-edge"><a class="anchorlink" href="#living-on-the-edge" data-turbo="false"><span>2.2</span> Living on the Edge</a></h3><p><code>Bundler</code> and <code>Gemfile</code> makes freezing your Rails application easy as pie with the new dedicated <code>bundle</code> command. If you want to bundle straight from the Git repository, you can pass the <code>--edge</code> flag:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">rails </span>new myapp <span class="nt">--edge</span> </code></pre> <button class="clipboard-button" data-clipboard-text="rails new myapp --edge ">Copy</button> </div> <p>If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the <code>--dev</code> flag:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">ruby</span> /path/to/rails/railties/bin/rails new myapp <span class="nt">--dev</span> </code></pre> <button class="clipboard-button" data-clipboard-text="ruby /path/to/rails/railties/bin/rails new myapp --dev ">Copy</button> </div> <h2 id="major-features"><a class="anchorlink" href="#major-features" data-turbo="false"><span>3</span> Major Features</a></h2><p><a href="https://guides.rubyonrails.org/images/4_0_release_notes/rails4_features.png"><img src="images/4_0_release_notes/rails4_features.png" alt="Rails 4.0"></a></p><h3 id="upgrade"><a class="anchorlink" href="#upgrade" data-turbo="false"><span>3.1</span> Upgrade</a></h3> <ul> <li><strong>Ruby 1.9.3</strong> (<a href="https://github.com/rails/rails/commit/a0380e808d3dbd2462df17f5d3b7fcd8bd812496">commit</a>) - Ruby 2.0 preferred; 1.9.3+ required</li> <li><strong><a href="https://www.youtube.com/watch?v=z6YgD6tVPQs">New deprecation policy</a></strong> - Deprecated features are warnings in Rails 4.0 and will be removed in Rails 4.1.</li> <li><strong>ActionPack page and action caching</strong> (<a href="https://github.com/rails/rails/commit/b0a7068564f0c95e7ef28fc39d0335ed17d93e90">commit</a>) - Page and action caching are extracted to a separate gem. Page and action caching requires too much manual intervention (manually expiring caches when the underlying model objects are updated). Instead, use Russian doll caching.</li> <li><strong>ActiveRecord observers</strong> (<a href="https://github.com/rails/rails/commit/ccecab3ba950a288b61a516bf9b6962e384aae0b">commit</a>) - Observers are extracted to a separate gem. Observers are only needed for page and action caching, and can lead to spaghetti code.</li> <li><strong>ActiveRecord session store</strong> (<a href="https://github.com/rails/rails/commit/0ffe19056c8e8b2f9ae9d487b896cad2ce9387ad">commit</a>) - The ActiveRecord session store is extracted to a separate gem. Storing sessions in SQL is costly. Instead, use cookie sessions, memcache sessions, or a custom session store.</li> <li><strong>ActiveModel mass assignment protection</strong> (<a href="https://github.com/rails/rails/commit/f8c9a4d3e88181cee644f91e1342bfe896ca64c6">commit</a>) - Rails 3 mass assignment protection is deprecated. Instead, use strong parameters.</li> <li><strong>ActiveResource</strong> (<a href="https://github.com/rails/rails/commit/f1637bf2bb00490203503fbd943b73406e043d1d">commit</a>) - ActiveResource is extracted to a separate gem. ActiveResource was not widely used.</li> <li><strong>vendor/plugins removed</strong> (<a href="https://github.com/rails/rails/commit/853de2bd9ac572735fa6cf59fcf827e485a231c3">commit</a>) - Use a <code>Gemfile</code> to manage installed gems.</li> </ul> <h3 id="actionpack"><a class="anchorlink" href="#actionpack" data-turbo="false"><span>3.2</span> ActionPack</a></h3> <ul> <li><strong>Strong parameters</strong> (<a href="https://github.com/rails/rails/commit/a8f6d5c6450a7fe058348a7f10a908352bb6c7fc">commit</a>) - Only allow permitted parameters to update model objects (<code>params.permit(:title, :text)</code>).</li> <li><strong>Routing concerns</strong> (<a href="https://github.com/rails/rails/commit/0dd24728a088fcb4ae616bb5d62734aca5276b1b">commit</a>) - In the routing DSL, factor out common subroutes (<code>comments</code> from <code>/posts/1/comments</code> and <code>/videos/1/comments</code>).</li> <li><strong>ActionController::Live</strong> (<a href="https://github.com/rails/rails/commit/af0a9f9eefaee3a8120cfd8d05cbc431af376da3">commit</a>) - Stream JSON with <code>response.stream</code>.</li> <li><strong>Declarative ETags</strong> (<a href="https://github.com/rails/rails/commit/ed5c938fa36995f06d4917d9543ba78ed506bb8d">commit</a>) - Add controller-level etag additions that will be part of the action etag computation.</li> <li><strong><a href="https://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works">Russian doll caching</a></strong> (<a href="https://github.com/rails/rails/commit/4154bf012d2bec2aae79e4a49aa94a70d3e91d49">commit</a>) - Cache nested fragments of views. Each fragment expires based on a set of dependencies (a cache key). The cache key is usually a template version number and a model object.</li> <li><strong>Turbolinks</strong> (<a href="https://github.com/rails/rails/commit/e35d8b18d0649c0ecc58f6b73df6b3c8d0c6bb74">commit</a>) - Serve only one initial HTML page. When the user navigates to another page, use pushState to update the URL and use AJAX to update the title and body.</li> <li><strong>Decouple ActionView from ActionController</strong> (<a href="https://github.com/rails/rails/commit/78b0934dd1bb84e8f093fb8ef95ca99b297b51cd">commit</a>) - ActionView was decoupled from ActionPack and will be moved to a separated gem in Rails 4.1.</li> <li><strong>Do not depend on ActiveModel</strong> (<a href="https://github.com/rails/rails/commit/166dbaa7526a96fdf046f093f25b0a134b277a68">commit</a>) - ActionPack no longer depends on ActiveModel.</li> </ul> <h3 id="general"><a class="anchorlink" href="#general" data-turbo="false"><span>3.3</span> General</a></h3> <ul> <li><strong>ActiveModel::Model</strong> (<a href="https://github.com/rails/rails/commit/3b822e91d1a6c4eab0064989bbd07aae3a6d0d08">commit</a>) - <code>ActiveModel::Model</code>, a mixin to make normal Ruby objects to work with ActionPack out of box (ex. for <code>form_for</code>)</li> <li><strong>New scope API</strong> (<a href="https://github.com/rails/rails/commit/50cbc03d18c5984347965a94027879623fc44cce">commit</a>) - Scopes must always use callables.</li> <li><strong>Schema cache dump</strong> (<a href="https://github.com/rails/rails/commit/5ca4fc95818047108e69e22d200e7a4a22969477">commit</a>) - To improve Rails boot time, instead of loading the schema directly from the database, load the schema from a dump file.</li> <li><strong>Support for specifying transaction isolation level</strong> (<a href="https://github.com/rails/rails/commit/392eeecc11a291e406db927a18b75f41b2658253">commit</a>) - Choose whether repeatable reads or improved performance (less locking) is more important.</li> <li><strong>Dalli</strong> (<a href="https://github.com/rails/rails/commit/82663306f428a5bbc90c511458432afb26d2f238">commit</a>) - Use Dalli memcache client for the memcache store.</li> <li><strong>Notifications start &amp; finish</strong> (<a href="https://github.com/rails/rails/commit/f08f8750a512f741acb004d0cebe210c5f949f28">commit</a>) - Active Support instrumentation reports start and finish notifications to subscribers.</li> <li><strong>Thread safe by default</strong> (<a href="https://github.com/rails/rails/commit/5d416b907864d99af55ebaa400fff217e17570cd">commit</a>) - Rails can run in threaded app servers without additional configuration.</li> </ul> <div class="interstitial note"><p>Check that the gems you are using are threadsafe.</p></div> <ul> <li><strong>PATCH verb</strong> (<a href="https://github.com/rails/rails/commit/eed9f2539e3ab5a68e798802f464b8e4e95e619e">commit</a>) - In Rails, PATCH replaces PUT. PATCH is used for partial updates of resources.</li> </ul> <h3 id="security"><a class="anchorlink" href="#security" data-turbo="false"><span>3.4</span> Security</a></h3> <ul> <li><strong>match do not catch all</strong> (<a href="https://github.com/rails/rails/commit/90d2802b71a6e89aedfe40564a37bd35f777e541">commit</a>) - In the routing DSL, match requires the HTTP verb or verbs to be specified.</li> <li><strong>html entities escaped by default</strong> (<a href="https://github.com/rails/rails/commit/5f189f41258b83d49012ec5a0678d827327e7543">commit</a>) - Strings rendered in erb are escaped unless wrapped with <code>raw</code> or <code>html_safe</code> is called.</li> <li><strong>New security headers</strong> (<a href="https://github.com/rails/rails/commit/6794e92b204572d75a07bd6413bdae6ae22d5a82">commit</a>) - Rails sends the following headers with every HTTP request: <code>X-Frame-Options</code> (prevents clickjacking by forbidding the browser from embedding the page in a frame), <code>X-XSS-Protection</code> (asks the browser to halt script injection) and <code>X-Content-Type-Options</code> (prevents the browser from opening a jpeg as an exe).</li> </ul> <h2 id="extraction-of-features-to-gems"><a class="anchorlink" href="#extraction-of-features-to-gems" data-turbo="false"><span>4</span> Extraction of features to gems</a></h2><p>In Rails 4.0, several features have been extracted into gems. You can simply add the extracted gems to your <code>Gemfile</code> to bring the functionality back.</p> <ul> <li>Hash-based &amp; Dynamic finder methods (<a href="https://github.com/rails/activerecord-deprecated_finders">GitHub</a>)</li> <li>Mass assignment protection in Active Record models (<a href="https://github.com/rails/protected_attributes">GitHub</a>, <a href="https://github.com/rails/rails/pull/7251">Pull Request</a>)</li> <li>ActiveRecord::SessionStore (<a href="https://github.com/rails/activerecord-session_store">GitHub</a>, <a href="https://github.com/rails/rails/pull/7436">Pull Request</a>)</li> <li>Active Record Observers (<a href="https://github.com/rails/rails-observers">GitHub</a>, <a href="https://github.com/rails/rails/commit/39e85b3b90c58449164673909a6f1893cba290b2">Commit</a>)</li> <li>Active Resource (<a href="https://github.com/rails/activeresource">GitHub</a>, <a href="https://github.com/rails/rails/pull/572">Pull Request</a>, <a href="http://yetimedia-blog-blog.tumblr.com/post/35233051627/activeresource-is-dead-long-live-activeresource">Blog</a>)</li> <li>Action Caching (<a href="https://github.com/rails/actionpack-action_caching">GitHub</a>, <a href="https://github.com/rails/rails/pull/7833">Pull Request</a>)</li> <li>Page Caching (<a href="https://github.com/rails/actionpack-page_caching">GitHub</a>, <a href="https://github.com/rails/rails/pull/7833">Pull Request</a>)</li> <li>Sprockets (<a href="https://github.com/rails/sprockets-rails">GitHub</a>)</li> <li>Performance tests (<a href="https://github.com/rails/rails-perftest">GitHub</a>, <a href="https://github.com/rails/rails/pull/8876">Pull Request</a>)</li> </ul> <h2 id="documentation"><a class="anchorlink" href="#documentation" data-turbo="false"><span>5</span> Documentation</a></h2> <ul> <li><p>Guides are rewritten in GitHub Flavored Markdown.</p></li> <li><p>Guides have a responsive design.</p></li> </ul> <h2 id="railties"><a class="anchorlink" href="#railties" data-turbo="false"><span>6</span> Railties</a></h2><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/railties/CHANGELOG.md">Changelog</a> for detailed changes.</p><h3 id="railties-notable-changes"><a class="anchorlink" href="#railties-notable-changes" data-turbo="false"><span>6.1</span> Notable changes</a></h3> <ul> <li><p>New test locations <code>test/models</code>, <code>test/helpers</code>, <code>test/controllers</code>, and <code>test/mailers</code>. Corresponding rake tasks added as well. (<a href="https://github.com/rails/rails/pull/7878">Pull Request</a>)</p></li> <li><p>Your app's executables now live in the <code>bin/</code> directory. Run <code>rake rails:update:bin</code> to get <code>bin/bundle</code>, <code>bin/rails</code>, and <code>bin/rake</code>.</p></li> <li><p>Threadsafe on by default</p></li> <li><p>Ability to use a custom builder by passing <code>--builder</code> (or <code>-b</code>) to <code>rails new</code> has been removed. Consider using application templates instead. (<a href="https://github.com/rails/rails/pull/9401">Pull Request</a>)</p></li> </ul> <h3 id="railties-deprecations"><a class="anchorlink" href="#railties-deprecations" data-turbo="false"><span>6.2</span> Deprecations</a></h3> <ul> <li><p><code>config.threadsafe!</code> is deprecated in favor of <code>config.eager_load</code> which provides a more fine grained control on what is eager loaded.</p></li> <li><p><code>Rails::Plugin</code> has gone. Instead of adding plugins to <code>vendor/plugins</code> use gems or bundler with path or git dependencies.</p></li> </ul> <h2 id="action-mailer"><a class="anchorlink" href="#action-mailer" data-turbo="false"><span>7</span> Action Mailer</a></h2><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md">Changelog</a> for detailed changes.</p><h3 id="action-mailer-notable-changes"><a class="anchorlink" href="#action-mailer-notable-changes" data-turbo="false"><span>7.1</span> Notable changes</a></h3><h3 id="action-mailer-deprecations"><a class="anchorlink" href="#action-mailer-deprecations" data-turbo="false"><span>7.2</span> Deprecations</a></h3><h2 id="active-model"><a class="anchorlink" href="#active-model" data-turbo="false"><span>8</span> Active Model</a></h2><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activemodel/CHANGELOG.md">Changelog</a> for detailed changes.</p><h3 id="active-model-notable-changes"><a class="anchorlink" href="#active-model-notable-changes" data-turbo="false"><span>8.1</span> Notable changes</a></h3> <ul> <li><p>Add <code>ActiveModel::ForbiddenAttributesProtection</code>, a simple module to protect attributes from mass assignment when non-permitted attributes are passed.</p></li> <li><p>Added <code>ActiveModel::Model</code>, a mixin to make Ruby objects work with Action Pack out of box.</p></li> </ul> <h3 id="active-model-deprecations"><a class="anchorlink" href="#active-model-deprecations" data-turbo="false"><span>8.2</span> Deprecations</a></h3><h2 id="active-support"><a class="anchorlink" href="#active-support" data-turbo="false"><span>9</span> Active Support</a></h2><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activesupport/CHANGELOG.md">Changelog</a> for detailed changes.</p><h3 id="active-support-notable-changes"><a class="anchorlink" href="#active-support-notable-changes" data-turbo="false"><span>9.1</span> Notable changes</a></h3> <ul> <li><p>Replace deprecated <code>memcache-client</code> gem with <code>dalli</code> in <code>ActiveSupport::Cache::MemCacheStore</code>.</p></li> <li><p>Optimize <code>ActiveSupport::Cache::Entry</code> to reduce memory and processing overhead.</p></li> <li><p>Inflections can now be defined per locale. <code>singularize</code> and <code>pluralize</code> accept locale as an extra argument.</p></li> <li><p><code>Object#try</code> will now return nil instead of raise a NoMethodError if the receiving object does not implement the method, but you can still get the old behavior by using the new <code>Object#try!</code>.</p></li> <li><p><code>String#to_date</code> now raises <code>ArgumentError: invalid date</code> instead of <code>NoMethodError: undefined method 'div' for nil:NilClass</code> when given an invalid date. It is now the same as <code>Date.parse</code>, and it accepts more invalid dates than 3.x, such as:</p><div class="interstitial code"> <pre><code class="highlight ruby"><span class="c1"># ActiveSupport 3.x</span> <span class="s2">"asdf"</span><span class="p">.</span><span class="nf">to_date</span> <span class="c1"># =&gt; NoMethodError: undefined method `div' for nil:NilClass</span> <span class="s2">"333"</span><span class="p">.</span><span class="nf">to_date</span> <span class="c1"># =&gt; NoMethodError: undefined method `div' for nil:NilClass</span> <span class="c1"># ActiveSupport 4</span> <span class="s2">"asdf"</span><span class="p">.</span><span class="nf">to_date</span> <span class="c1"># =&gt; ArgumentError: invalid date</span> <span class="s2">"333"</span><span class="p">.</span><span class="nf">to_date</span> <span class="c1"># =&gt; Fri, 29 Nov 2013</span> </code></pre> <button class="clipboard-button" data-clipboard-text="# ActiveSupport 3.x &quot;asdf&quot;.to_date # => NoMethodError: undefined method `div' for nil:NilClass &quot;333&quot;.to_date # => NoMethodError: undefined method `div' for nil:NilClass # ActiveSupport 4 &quot;asdf&quot;.to_date # => ArgumentError: invalid date &quot;333&quot;.to_date # => Fri, 29 Nov 2013 ">Copy</button> </div></li> </ul> <h3 id="active-support-deprecations"><a class="anchorlink" href="#active-support-deprecations" data-turbo="false"><span>9.2</span> Deprecations</a></h3> <ul> <li><p>Deprecate <code>ActiveSupport::TestCase#pending</code> method, use <code>skip</code> from minitest instead.</p></li> <li><p><code>ActiveSupport::Benchmarkable#silence</code> has been deprecated due to its lack of thread safety. It will be removed without replacement in Rails 4.1.</p></li> <li><p><code>ActiveSupport::JSON::Variable</code> is deprecated. Define your own <code>#as_json</code> and <code>#encode_json</code> methods for custom JSON string literals.</p></li> <li><p>Deprecates the compatibility method <code>Module#local_constant_names</code>, use <code>Module#local_constants</code> instead (which returns symbols).</p></li> <li><p><code>ActiveSupport::BufferedLogger</code> is deprecated. Use <code>ActiveSupport::Logger</code>, or the logger from Ruby standard library.</p></li> <li><p>Deprecate <code>assert_present</code> and <code>assert_blank</code> in favor of <code>assert object.blank?</code> and <code>assert object.present?</code></p></li> </ul> <h2 id="action-pack"><a class="anchorlink" href="#action-pack" data-turbo="false"><span>10</span> Action Pack</a></h2><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/actionpack/CHANGELOG.md">Changelog</a> for detailed changes.</p><h3 id="action-pack-notable-changes"><a class="anchorlink" href="#action-pack-notable-changes" data-turbo="false"><span>10.1</span> Notable changes</a></h3> <ul> <li>Change the stylesheet of exception pages for development mode. Additionally display also the line of code and fragment that raised the exception in all exceptions pages.</li> </ul> <h3 id="action-pack-deprecations"><a class="anchorlink" href="#action-pack-deprecations" data-turbo="false"><span>10.2</span> Deprecations</a></h3><h2 id="active-record"><a class="anchorlink" href="#active-record" data-turbo="false"><span>11</span> Active Record</a></h2><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md">Changelog</a> for detailed changes.</p><h3 id="active-record-notable-changes"><a class="anchorlink" href="#active-record-notable-changes" data-turbo="false"><span>11.1</span> Notable changes</a></h3> <ul> <li><p>Improve ways to write <code>change</code> migrations, making the old <code>up</code> &amp; <code>down</code> methods no longer necessary.</p> <ul> <li>The methods <code>drop_table</code> and <code>remove_column</code> are now reversible, as long as the necessary information is given. The method <code>remove_column</code> used to accept multiple column names; instead use <code>remove_columns</code> (which is not revertible). The method <code>change_table</code> is also reversible, as long as its block doesn't call <code>remove</code>, <code>change</code> or <code>change_default</code></li> <li>New method <code>reversible</code> makes it possible to specify code to be run when migrating up or down. See the <a href="https://github.com/rails/rails/blob/main/guides/source/active_record_migrations.md#using-reversible">Guide on Migration</a></li> <li>New method <code>revert</code> will revert a whole migration or the given block. If migrating down, the given migration / block is run normally. See the <a href="https://github.com/rails/rails/blob/main/guides/source/active_record_migrations.md#reverting-previous-migrations">Guide on Migration</a></li> </ul></li> <li><p>Adds PostgreSQL array type support. Any datatype can be used to create an array column, with full migration and schema dumper support.</p></li> <li><p>Add <code>Relation#load</code> to explicitly load the record and return <code>self</code>.</p></li> <li><p><code>Model.all</code> now returns an <code>ActiveRecord::Relation</code>, rather than an array of records. Use <code>Relation#to_a</code> if you really want an array. In some specific cases, this may cause breakage when upgrading.</p></li> <li><p>Added <code>ActiveRecord::Migration.check_pending!</code> that raises an error if migrations are pending.</p></li> <li><p>Added custom coders support for <code>ActiveRecord::Store</code>. Now you can set your custom coder like this:</p><div class="interstitial code"> <pre><code class="highlight plaintext">store :settings, accessors: [ :color, :homepage ], coder: JSON </code></pre> <button class="clipboard-button" data-clipboard-text="store :settings, accessors: [ :color, :homepage ], coder: JSON ">Copy</button> </div></li> <li><p><code>mysql</code> and <code>mysql2</code> connections will set <code>SQL_MODE=STRICT_ALL_TABLES</code> by default to avoid silent data loss. This can be disabled by specifying <code>strict: false</code> in your <code>database.yml</code>.</p></li> <li><p>Remove IdentityMap.</p></li> <li><p>Remove automatic execution of EXPLAIN queries. The option <code>active_record.auto_explain_threshold_in_seconds</code> is no longer used and should be removed.</p></li> <li><p>Adds <code>ActiveRecord::NullRelation</code> and <code>ActiveRecord::Relation#none</code> implementing the null object pattern for the Relation class.</p></li> <li><p>Added <code>create_join_table</code> migration helper to create HABTM join tables.</p></li> <li><p>Allows PostgreSQL hstore records to be created.</p></li> </ul> <h3 id="active-record-deprecations"><a class="anchorlink" href="#active-record-deprecations" data-turbo="false"><span>11.2</span> Deprecations</a></h3> <ul> <li><p>Deprecated the old-style hash based finder API. This means that methods which previously accepted "finder options" no longer do.</p></li> <li><p>All dynamic methods except for <code>find_by_...</code> and <code>find_by_...!</code> are deprecated. Here's how you can rewrite the code:</p> <ul> <li><code>find_all_by_...</code> can be rewritten using <code>where(...)</code>.</li> <li><code>find_last_by_...</code> can be rewritten using <code>where(...).last</code>.</li> <li><code>scoped_by_...</code> can be rewritten using <code>where(...)</code>.</li> <li><code>find_or_initialize_by_...</code> can be rewritten using <code>find_or_initialize_by(...)</code>.</li> <li><code>find_or_create_by_...</code> can be rewritten using <code>find_or_create_by(...)</code>.</li> <li><code>find_or_create_by_...!</code> can be rewritten using <code>find_or_create_by!(...)</code>.</li> </ul></li> </ul> <h2 id="credits"><a class="anchorlink" href="#credits" data-turbo="false"><span>12</span> Credits</a></h2><p>See the <a href="https://contributors.rubyonrails.org/">full list of contributors to Rails</a> for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.</p> </section> <hr> <footer aria-labelledby="heading-feedback" role="region"> <h2 id="heading-feedback">Feedback</h2> <p> You're encouraged to help improve the quality of this guide. </p> <p> Please contribute if you see any typos or factual errors. To get started, you can read our <a href="https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section. </p> <p> You may also find incomplete content or stuff that is not up to date. Please do add any missing documentation for main. Make sure to check <a href="https://edgeguides.rubyonrails.org">Edge Guides</a> first to verify if the issues are already fixed or not on the main branch. Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a> for style and conventions. </p> <p> If for whatever reason you spot something to fix but cannot patch it yourself, please <a href="https://github.com/rails/rails/issues">open an issue</a>. </p> <p>And last but not least, any kind of discussion regarding Ruby on Rails documentation is very welcome on the <a href="https://discuss.rubyonrails.org/c/rubyonrails-docs">official Ruby on Rails Forum</a>. </p> </footer> </div> </article> </main> <hr class="hide" /> <footer id="complementary"> <div class="wrapper"> <p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p> <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p> </div> </footer> <a href="#main-skip-link" class="back-to-top" data-turbo="false"><span class="visibly-hidden">Back to top</span></a> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10