BigBinary Blog
We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.
Rails 6.0 was recently released.
As per rails/rails#34754, a Rails 6 app requires Ruby version 2.5 or newer.
Let's discuss what we need to know if we are dealing with Rails 6.
While creating a new Rails 6 app, we need to ensure that the current Ruby version in the shell is set to 2.5 or newer.
If it is set to an older version
then the same version will be used
by the rails new
command
to
set the Ruby version in
.ruby-version
and in Gemfile
respectively
in the created Rails app.
\$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
\$ rails new meme-wizard
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create Gemfile
[...] omitted the rest of the output
\$ cd meme-wizard && grep -C 2 -Rn -a "2.3.1" .
./.ruby-version:1:2.3.1
--
--
./Gemfile-2-git_source(:github) { |repo| "https://github.com/#{repo}.git" }
./Gemfile-3-
./Gemfile:4:ruby '2.3.1'
./Gemfile-5-
./Gemfile-6-# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
An easy fix for this
is to install a Ruby version 2.5 or newer
and
use that version prior to running the rails new
command.
\$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
\$ rbenv local 2.6.0
\$ ruby -v
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
\$ rails new meme-wizard
\$ cd meme-wizard && grep -C 2 -Rn -a "2.6.0" .
./.ruby-version:1:2.6.0
--
--
./Gemfile-2-git_source(:github) { |repo| "https://github.com/#{repo}.git" }
./Gemfile-3-
./Gemfile:4:ruby '2.6.0'
./Gemfile-5-
./Gemfile-6-# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
While upgrading an older Rails app to Rails 6,
we need to update the Ruby version to 2.5 or newer
in .ruby-version
and Gemfile
files respectively.
Since
Ruby 2.5 has added Hash#slice
method,
the extension method with the same name
defined by
activesupport/lib/active_support/core_ext/hash/slice.rb
has been
removed from Rails 6.
Similarly,
Rails 6 has also
removed
the extension methods
Hash#transform_values
and
Hash#transform_values!
from Active Support
in favor of the native methods with the same names
which exist in Ruby.
These methods were
introduced in Ruby 2.4 natively.
If we try to explicitly require
active_support/core_ext/hash/transform_values
then it would print a deprecation warning.
> > require "active_support/core_ext/hash/transform_values"
# DEPRECATION WARNING: Ruby 2.5+ (required by Rails 6) provides Hash#transform_values natively, so requiring active_support/core_ext/hash/transform_values is no longer necessary. Requiring it will raise LoadError in Rails 6.1. (called from irb_binding at (irb):1)
=> true