It’s basic, but easy to forget if you haven’t used it for a while, so here’s a memo.
The process to add and enable a gem is as follows:
- Add to Gemfile. e.g.
gem 'sqlite3' - Run
bundle install
Depending on the gem, there may be additional steps from here, but enabling the gem itself follows this process.
About Where to Write gem GEM_NAME
Gems that are always used, Gems that directly affect the client-side UI, or Gems related to models and controllers are placed outside of the group method blocks in the Gemfile.
Important Gems like rails and sqlite3 fall into this category.
Gems like hirb, which makes the output of rails c more readable, don’t need to be used in :production, and in fact, it’s better not to include unnecessary gems to prevent wasteful errors.
So, as shown below, make it active only in the :development development environment.
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]
gem 'hirb' # Gem for displaying model output results in table format
gem 'hirb-unicode' # Handles output alignment issues with multibyte characters like Japanese
end