What Is New in Ruby on Rails 5.1
| Category | Highlights |
|---|---|
| New Features | Yarn integration for npm packages, optional Webpacker via the --webpack flag, rails-ujs replaces jQuery as the default UJS adapter, built-in System test support with Capybara, encrypted secrets management, parameterized mailers, new routing helpers direct and resolve, unified form_with helper. |
| Improvements | Unified form handling reduces API surface, default UJS now vanilla JS, ActiveSupport duration helpers gain #before and #after, ActiveJob adds declarative retry_on and discard_on, ActiveRecord primary keys default to BIGINT, better batch limits and connection-pool stats. |
| Breaking Changes | Transactional tests now wrap *all* DB connections, jQuery-rails removed from the default stack, deprecated config.static_cache_control and config.serve_static_files eliminated, old Rails tasks (rails:update, rails:template etc.) removed, -j option dropped from rails new, integration test methods no longer accept non-keyword arguments, removed :text and :nothing render options, HashWithIndifferentAccess methods on ActionController::Parameters gone. |
| Deprecations | config.action_controller.raise_on_unfiltered_parameters is now a no-op, Erubis ERB handler deprecated in favor of Erubi, top-level HashWithIndifferentAccess class soft-deprecated, string arguments for :if/:unless in callbacks deprecated, several ActiveRecord and ActiveJob APIs marked deprecated. |
How does Rails 5.1 change JavaScript asset management?
Rails 5.1 introduces Yarn for npm package management and makes Webpacker optional via the --webpack flag.
- Yarn is now generated in new apps with a
package.jsonand a binstub, letting you pull in libraries such as React or Vue directly from npm. - Webpacker integrates seamlessly with the asset pipeline; you can keep images, fonts, and legacy JavaScript in
app/assetswhile bundling modern JavaScript through Webpack. - jQuery is no longer a default dependency; the new
rails-ujsdriver ships with Action View and works out-of-the-box fordata-remoteanddata-confirmattributes.
# Example: adding a library with Yarn
yarn add axios
# Then import in app/javascript/packs/application.js
import axios from 'axios'
What testing capabilities are built into Rails 5.1?
Rails 5.1 adds first-class System tests powered by Capybara and updates transactional test handling.
- Generate a system test with
rails generate system_test example; Rails configures Capybara, a headless Chrome driver, and automatic screenshot capture on failures. - All Active Record connections now share the same transaction during tests, preventing flaky data visibility when spawning threads.
- If you rely on separate connections in threaded tests, you can disable the new behavior by turning off
use_transactional_testsfor the affected test case.
How are application secrets stored securely in Rails 5.1?
Rails 5.1 provides encrypted secrets that keep credentials out of source control.
- Run
bin/rails secrets:setupto generateconfig/secrets.yml.encand a master key. - The master key must be stored outside the repository (e.g., in
RAILS_MASTER_KEYenv var or a separatemaster.keyfile). - At runtime Rails decrypts the file automatically, so you can safely commit the encrypted version.
# config/secrets.yml.enc (encrypted)
production:
secret_key_base: <encrypted>
What changes affect form handling and routing in Rails 5.1?
Rails 5.1 unifies form helpers with form_with and adds new routing DSL methods direct and resolve.
form_withreplacesform_forandform_tag, automatically inferring URLs from models or accepting expliciturlandscopeoptions.- Use
directto create custom URL helpers that return anyurl_for-compatible value. - Use
resolveto customize polymorphic routing, e.g., mapping aBasketmodel to a singular/basketpath.
# Example: custom helper
direct(:homepage) { "https://rubyonrails.org" }
# Usage
homepage_url # => "https://rubyonrails.org"
Frequently Asked Questions
Do I need to install Yarn manually before creating a new Rails 5.1 app?
You can rely on the Yarn binstub generated by rails new, but having Yarn installed globally is recommended.
Is jQuery completely removed from Rails 5.1?
jQuery is no longer included by default; you can still add it via Yarn if your code depends on it.
How do I enable Webpacker in an existing Rails 5.0 project?
Add the webpacker gem to your Gemfile and run bundle exec rails webpacker:install to set up the configuration.
Can I run System tests without a Chrome browser installed?
Rails defaults to headless Chrome, but you can configure Capybara to use Selenium with Firefox if needed.
What command creates the encrypted secrets file?
Run bin/rails secrets:setup to generate config/secrets.yml.enc and a master key.
Will my existing integration tests break because of the non-keyword argument removal?
Yes, you must update calls like get :show, id: 1 to the keyword style get :show, params: { id: 1 }.