Sometimes you’re working your way through Michael Hartl’s Rails Tutorial and you have just finished chapter 2 when something urgent commands your attention. It continues to command your attention for like a full week and then you decide to get back to it. Chapter 3 hits and Hartl’s telling you to deploy your app to Heroku, with no other explicit instructions except to repeat what you did last time. But it’s been a week, and you have no idea.
You could even say you’ve been derailed.
(*crickets*)
You’d really like to just get a move on with this, and don’t want to read the whole damn book again. Not that it wasn’t delightful to read the first time. So what are you going to do? Sit around until someone explicitly writes a blog post telling you what to do?
Anyway, I wrote you a nice little guide on how do deploy a rails app to Heroku. No frills. No answering questions like “Why do you do that?” or “What’s the mac version of this command?” (I’m on a Windows machine, by the way) or “Where do babies come from?”. Nope. Just a quick checklist.
Because you need it.
Because you want it.
Because if it makes your life that much easier, it was worth skimming reading this dumb intro paragraph.
Okay, you don’t have to be so pushy!
- On your command line, navigate (cd) into folder you want to create the app folder in (workspaces, in the case of Hartl’s)
- Command line:
rails _4.2.1_ new name_of_app
- replace “4.2.1” with the version number in use, obviously
- can check which version of rails you have by using the command
rails -v
- The command line will do a bunch of things and then will be done
- Go to folder (GUI, not command line) and check that it’s been populated
- Open gemfile and make sure it has everything you need
- Command line:
bundle install
(or, apparently, justbundle
will work, too.- can leave out groups by appending with
--without group
- can leave out groups by appending with
bundle update
- Push to git repository
git init
git add -A
git commit -a "Initialize repository" - Hartl recommends changing readme file from rdoc to md by going:
git mv README.rdoc README.md
- Create a new repository in bitbucket or github or where-ever
- push your repository up to service
git remote add origin git@bitbucket.org:<username>/app_name.git
git push -u origin --all - Get a basic “hello world” page up by:
- go to app folder within the folder created for app_name
- go to app > controllers > application controllers and open that file
- add the lines:
def hello
render text: "hello, world!"
end
- Save that file then go to the config folder from the root app folder and edit the “routes” file
- uncomment the root route line and add
'controller#hello'
instead of"welcome#index"
- save that file
- commit changes by:
git commit -am "Add hello"
- Push to heroku
heroku create
git push heroku master - Your silly app is now on heroku slash the web
Well now you’ve got a killer one-page app on Heroku that just says “Hello, world!”. *clapping hands emoji* Congrats! Now stop getting distracted so easily and get to it.