Things I Couldn’t Figure Out Then Figured Out in Ruby On Rails — Part 1

Morgan Fogarty
Jan 26, 2019 · 3 min read

I went to a Ruby hacknight the other night! There, I spent an hour and a half pair-debugging what turned out to be a painfully simple issue.

The issue I was having:

I needed to generate a migration: rails generate migration add_product_url_to_wishlists. But when I would type that into the terminal, I would get the following error:

The answer is definitely in this error message 🤦‍♀

Other behavior:

  • rails console produced the same error as the generate migration command.

But:

  • rails server ran successfully.

I should mention that my view of the error message was not as it looks above. I have, before now, kept the terminal text large and more readable, which makes the error message broken up and scrollable and perhaps… less readable. I think I may have seen it if I’d looked at it as it’s pictured above. But who knows?!

Here’s what I did to try and fix it:

  • Made sure I was using the correct command to generate the migration. I was! Yay.
  • Stopped/started the server.
  • Ran the migration command with bundle exec.
  • Checked my other Rails projects to see if they were having errors. They were not.
  • Googled the first couple lines of the error message, which lead me to:

— Comment out bootsnap in my Gemfile. Then uncomment it out.

— Add config.autoload_paths += %W(#{config.root}/lib) to the DressMe module in application.rb. Then delete that line.

Last ditch efforts, I:

  • Cleared the cache.
  • Bundled.
  • Bundle updated.

Lastest ditchest of efforts, I:

  • Restarted my computer.

After more googling with my pair, we:

  • Did all the things I had previously done, to make sure nothing had fallen through the cracks (he was baffled that rails server worked, but rails console did not.
  • Typed which ruby and which rails in the command line to see if we were using the correct versions for the project.
  • Stopped Spring with the stop spring command.
  • My pair pulled down the repo and we both checked out very old commits* (He got the same errors that I was getting).
  • More googling.
  • More cache clearing.

Then we talked about the most recent additions I’d made to the app. I had added the auto-links gem a couple days before. It allows urls to be clickable. So, we did a bit more googling and error message reading with auto-links in mind. And then the answer revealed itself.

The error was occurring because… the first few lines of my application.rb file looked like this:

Wrong

Not like this:

Right!

The error was occurring because Ruby was trying to load the rails_autolink gem, which depended on Rails, which hadn’t been loaded yet.

This was fun. I learned things! And we solved the problem together!

  1. I learned that I’d like to keep my terminal text size a bit smaller, so I can read the whole error message at once without scrolling.
  2. I learned that reading the whole error message can help figure out the… error.
  3. I learned that the require order is important in application.rb.
  4. I learned how to clear my cache.
  5. I learned how to stop Spring, and why we use it or need it.

*It doesn’t make sense to me that even with older commits we were getting the same errors, if I’d added this Gem and line of code only a few days before. If anyone has info about why that would be, please do tell.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store