Dealing with errors

Search icon
Search Book

In this chapter, we will take a look at some common errors that occur during Rails development and how to fix these errors

rbenv path not added

If the rbenv path is not added in the .zshrc config file then the following error can appear:

1WARNING: You don’t have /Users/id/.gem/ruby/2.6.0/bin in your PATH,
2	 gem executables will not run.
3Successfully installed rails-

To fix this, verify that rbenv path is added in the .zshrc using the following command:

1code ~/.zshrc

The above command will open the .zshrc file. In this file check for the rbenv path. If the path is not found then add the following lines to the config file and save it:

1# path to rbenv installation
2export PATH="$HOME/.rbenv/bin:$PATH"
3# initialize rbenv on startup
4eval "$(rbenv init -)"

Webpacker compatibility issue

There can be compatibility issues with some versions of webpacker. Please read the webpacker module and version issues section for more info.

Take a look at the setting up a webpack version section in this book for steps to fix the webpacker compatibility issues.

rails command does not exist

Sometimes the following error can occur on running a command like bundle exec rails server:

1The rails command exists in these Ruby versions:
2  3.0.xx

This error can occur if the rails gem is installed in a different Ruby version than the one being used globally. To fix this you should first set the desired Ruby version as the global version and then install the rails gem in that version.

For example, to set the global ruby version to 3.0.4, run the following command:

1rbenv global 3.0.4
2gem install rails

Make sure that the required Ruby version is installed in the system. You can check which versions are installed using the following command:

1rbenv versions

To install another Ruby version, you should first update the ruby-build to get an updated list of all the available versions. Run the following command to do so:

1brew upgrade ruby-build

Now check the available versions using the following command:

1rbenv install --list

Ruby and Apple Silicon

If you are using Apple silicon, then you can run into issues while installing a Ruby version because your computer could have two different brew installations. One for arm architecture under the /opt/homebrew directory and another one for the Intel architecture(using Rosetta) under the usr/local directory.

To avoid such issues remove the arm version and make sure the terminal is using Rosetta. Please refer to this section for steps to remove the arm brew and then refer to enabling Rosetta on Mac section for steps to install homebrew under Rosetta.

Fixing failing ruby-build

You can get the following error if your ruby-build is failing during an operation:

1BUILD FAILED (macOS 11.6.1 using ruby-build 20211019)
3Inspect or clean up the working tree at /var/folders/ck/wxjp95sj2d90dd1ls1zsnf8c0000gn/T/ruby-build.20211102122424.5245.ifbDiJ
4Results logged to /var/folders/ck/wxjp95sj2d90dd1ls1zsnf8c0000gn/T/ruby-build.20211102122424.5245.log
6Last 10 log lines:
7The Ruby yaml extension was not compiled.
8ERROR: Ruby install aborted due to missing extensions

To fix this issue, remove the command line tools and reinstall xcode using the following command:

1sudo rm -rf /Library/Developer/CommandLineTools
2xcode-select --install

Then install the necessary packages:

1brew install rbenv ruby-build openssl readline libyaml zlib

No response from PostgreSQL service

Using an arm terminal to start the PostgreSQL service when it is installed in the Intel compiled brew can lead to an error. You can verify the error by running the following command:

1brew services list

The issue can be resolved by stopping the service from the arm terminal and quitting the terminal and starting the service from the Rosetta terminal.

You can start or stop a service using the following commands:

1# start a service
2brew start service_name
3# stop a service
4brew stop service_name

Sass syntax error in production

If the assets aren't pre-compiled in production then adding tailwind imports to your application.css file can throw the following error:

1SassC::SyntaxError: Error: File to import not found or unreadable: tailwindcss/base.
2        on line 17:2 of stdin
3     >>  @import "tailwindcss/base";

This can happen, if tailwindcss is listed as a devDependency in your package.json file. To fix this move tailwindcss to the dependencies section of package.json.

Miscellaneous errors

  • Often developers miss out on restarting the server after making changes to the Rails config files or application secrets files. These files are only loaded once when the server is started hence it is a good practice to restart the server after making a change to such files to avoid any errors.

  • Avoid syntax errors. For example missing out on colons or not ending a block can lead to syntax errors. These are hard to catch. Best way to check the line number in the stacktrace and look at the codebase.