Each version, rails will have different updates. Rails is just a framework so the differences here are syntaxes. In a project, the syntaxes are not only in source code but also in dependencies or gems. Thus, we have to upgrade gems as well.
- Updating gems to have corresponding rails syntaxes.
- Modifying source code respecting to new rails version syntaxes.
Firstly, we upgrade dependencies to correct versions:
We modify Gemfile or Gemlock, reinstall or update gem to proper version working with the target rails version.
The good way to do this is generating a new project with specific rails version. Let’s see the version we have in local:
gem list rails --local
Generate new project with version:
rails _6.1.4.1_ new rails-6.1.4.1
Now look at new Gemfile of this version:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
We copy these dependencies to current project which need to be upgraded. Run this command after changing versions:
bundle update
This command will install new version gems and update Gemfile.lock
Here we are done with dependencies upgrade. We now need to fix runtime issues. Run below command to generate necessary files for new rails version:
rails app:update
Rails 5.x to 6.x
We need to install webpacker.
rails webpacker:install
We might see this issue:
rails aborted!
Sprockets::Railtie::ManifestNeededError: Expected to find a manifest file inapp/assets/config/manifest.js
But did not, please create this file and use it to link any assets that need
to be rendered by your app:Example:
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
and restart your server
Create manfifest.js file as instruction and re-run above command.
Now, we have to fix issue related to webpacker. Upgrade is done.
Thanks for your blog, nice to read. Do not stop.
Thanks Mark. Hope you can find useful info here.