Le Wagon — 4 Tips and Tricks for Project Week Your TAs Don’t Want You to Know About 🙊

Paulo D’Alberti
4 min readNov 14, 2021

Congratulations! You’ve made it to Project Week. You are now in the most hectic period of the bootcamp. As such, you’ll want to use all possible tools to speed up your development process. Now, your teachers and TAs won’t tell you about these tools as they want you to concentrate on using what you’ve already learnt and not get “confused”. Which means you are the smart ones that will have a competitive edge over other teams 😉.

Without further ado, here are four tips and tricks your TAs don’t want you to know about!

Shorter git commands

You’ve learnt the basic commands for pulling, pushing, committing and checking out. But you probably don’t know there are shorter versions of what you’ve learnt! Here they are together with their standard counterparts:

  • ggpush ==git push origin <branch-name>
  • ggpull ==git pull origin <branch-name>
  • gco == git checkout
  • gc -am "message" == git add . + git commit -m "message" (DISCLAIMER: it will work only on modified files, not newly created ones)
  • and finally gst == git status (though I personally prefer git st as the output is more concise)
All that saved time on typing!

Reset IDs when re-running seeds

We’ve all had this issue: you are preparing the seeds for your apps and you need some model instances to be directly related to other ones, so you assign them via ID. This works nice and well because you keep dropping and re-creating your database (a terrible practice, honestly) so the IDs always reset, but then you push to Heroku where you can’t drop anymore and suddenly it doesn’t work anymore!

The standard solution to this problem would be to add some logic (usually involving math) that will allow you to find the matching model. But I have good news for you! There is a gem that will reset the IDs of your database without having to drop it. Plus a nice bonus: you won’t have to use .destroy_all anymore!

Here is how to set it up:

  1. Add gem 'database_cleaner-active_record' to your Gemfile
  2. Run bundle install
  3. At the very beginning of your db/seeds.rb add the following lines:
require 'database_cleaner/active_record'DatabaseCleaner.allow_production = true                             DatabaseCleaner.allow_remote_database_url = true                             DatabaseCleaner.strategy = :truncation                             DatabaseCleaner.clean# write your seeds below this line

Voilá! Now every time you run rails db:seed your database will be cleaned and the IDs reset before creating new entries.

Automatically deploy to Heroku

There’s little more annoying than having everything working nice and well on your machine but not on Heroku, only to later find out that it was because you forgot to push there… Luckily, there is a way to solve this and in the process streamline your development process so that whatever you have on your GitHub’s master/main branch will be automatically on Heroku!

The power of automation, now delivered directly to your application.

Here is how to set it up:

  1. Go to your app’s dashboard on Heroku (url should be something like https://dashboard.heroku.com/apps/app-name )
  2. Click on Deploy (https://dashboard.heroku.com/apps/app-name/deploy/heroku-git)
  3. In Deployment Method select GitHub (https://dashboard.heroku.com/apps/app-name/deploy/github)
  4. Enable Heroku extension on GitHub
  5. Search for the repository you want to connect to and click Connect
  6. Select deployment branch (master or main)
  7. Enable Automatic Deploys (no need to tick “Wait for CI to pass before deploy”)

And there you have it. Just make sure you properly check every PR before merging it to master all you’ll be good to go 😁.

Display Rails error page on Heroku

When you are running a server in your development environment and you write some buggy code (like calling a method on nil, or calling an undefined method) Rails does a very good job of generating a page in white and red telling you clearly what the error is, where the code is present, and giving you and environment to run some commands. Heroku on the other hand just gives you a generic “an error has happened” page.

Yes, I know that something went wrong, thank you very much. Would you be so kind and tell me what did?

Wouldn’t it be nice to have the same Rails page from development on Heroku? Well, you can!

In your config/environments/production.rb change the line config.consider_all_requests_local = false to config.consider_all_requests_local = true

That’s all that it takes — commit and deploy to Heroku (or have it deployed automatically thanks to the previous advice), and enjoy the detailed error messages!

Like these tips and tricks? Clap for the article! Think that there are some other cool ones that I’ve missed? Let me know in the comments. And as always — thanks for reading.

--

--