Debugging 5 Common Localhost Errors

I keep getting this error

“I keep getting this error!”

A huge part of what we do here at BaseRails is helping you troubleshoot errors. For everyone who’s learning to code, there’s a steep learning curve in reading error messages and actually understanding how to fix them. I used to dread the red and white error page that showed up instead of my actual app. It would make me feel helpless and frustrated and I’d sometimes break other parts of my app while trying to fix the problem. The worst of the errors would set me back by days, Googling all the keywords I could think of, yet unable to understand the technical terms on any of the 15 tabs I’d opened. Note: if this happens to you while going through BaseRails, please email us and we’ll help!

When you go through our course, we expect you to encounter these error messages sometimes – occasionally, we even intend for this to happen! It’s all a natural part of the learning process. We’ve had students email us with their screenshots when they encounter these errors and I’ve compiled a list of some common errors you’ll see on localhost and what to do about it.

#1.  Error photo-Rails server

If you go to localhost:3000 and get this error message or something else along the lines of “…could not connect to localhost:3000″, this just means your Rails server isn’t running. Go into your command line, make sure you navigate into your app folder, and type “rails server”. Once it’s running, go back to your browser and refresh the page. It should now be running.

#2 error-migration

When you see a “PendingMigrationError”, it means you’ve asked Rails to change your database, but you haven’t finished making the changes. To actually initiate this change, go into your command line and type”rake db:migrate”. Whenever you run this command, you have to also remember to restart your Rails server by quitting out of it (type “Command+C”) and then reopening it (type “rails server”).

#3 error-syntax

“SyntaxError” occurs when you have a typo–usually a rogue period, a misplaced bracket, or a forgotten tag. The error message will tell you which file contains the typo–look inside the parentheses right before the “Extracted source” box. The message will also try to tell you the specific line in your file which contains the typo. It’s not always accurate though so don’t put too much faith in what it says. Just know that your typo is somewhere in that file, so fine-comb it until you find the mistake. Then simply refresh the page to see if you’ve fixed it.

#4 error-routeing

Routing errors occur when you try to access a URL that doesn’t exist. Either you’ve typed in the wrong URL or you forgot to set up the route in your config/routes.rb file. The paths they show you at the bottom of the error message are the URLs that currently exist for your app. If your URL doesn’t appear in the listed paths, double-check your routes.rb file.

#5 error-name

A “NameError” means that you’ve probably typed the wrong name somewhere. Usually, this happens when you used the singular instead of the plural, or vice versa. For example, you may have typed “listing_controller” when it should be “listings_controller”. Double-check the highlighted line and make sure you’ve used the right name.

After you’ve seen these error messages a few times, you’ll become more familiar with debugging them. Almost everything in programming boils down to pattern recognition. Practice makes perfect. Don’t forget the tried-and-true method of all developers: when in doubt, Google the error message. Someone else has probably had to solve that same problem as you, and hopefully they posted a solution on how to fix it. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>