Skip to content

Instantly share code, notes, and snippets.

@tibbon
Created April 15, 2012 15:57
Show Gist options
  • Save tibbon/2393556 to your computer and use it in GitHub Desktop.
Save tibbon/2393556 to your computer and use it in GitHub Desktop.
Helping Dave S get started on Rails 3.x with Heroku
# This creates your rails site in the directory called 'davesite'. You can replace 'davesite' with anything that starts with a letter.
rails new davesite
#Change to the davesite directory.
cd davesite
#Logs you onto Heroku. You only really need to do this once unless you have multiple accounts
heroku login
#Use a text editor to alter the Gemfile in this directory.
#Remove the line: gem 'sqlite3'
#Put in the following in the Gemfile instead.
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'thin'
end
#What this does is makes it so that you're using Postgres for the database in production (heroku) and in development (your local box) it uses sqlite3. Postgres is a bigger and heavier duty database, and sqlite3 is really simple. Largely in Rails development they are compatible, but you'd never use sqlite3 in production. sqlite3 is easy to setup and use however, so great for your local machine.
#Back on the commandline, type:
bundle install
#Also on the commandline type. This generates a 'scaffold' for your site around an object. Basically it creates a lot of files that you can edit later, but also sets up stuff in the database for you
rails g scaffold Guitars name:string price:decimal description:text color:string
# This runs the 'migration' that is created on your local database.
rake db:migrate
#Add your app to git
git init #Creates a hidden .git directory that stores all the git config stuff
git add . #Adds all the files in the directory (minus any noted in the .gitignore file) to the git repo
git commit -m "Initial commit" #Creates a commit for it. This is like a 'savepoint' that you could return to
#This will add a 'remote' to git of Github for you. This is where you should store your code. Heroku is where you deploy to using Git. Github is like the best backup in the world, plus more
#The last URL section of this you'll have to modify.
#Go to https://github.com/repositories/new to create a new repo and get the URL that you put on the end of this command
git remote add origin git@github.com:username/Hello-World.git
#Copies the code to Github
git push origin master
#Create a Heroku Cedar stack. This sets up a new app in Heroku for you
heroku create --stack cedar
#Push the code to Heroku. This is like a really fancy 'copy' to Heroku, but will also run all sorts of scripts and stuff.
git push heroku master
heroku run rake db:migrate
#Takes you to the Heroku site you just made
heroku open
#You'll probably have to add /guitars to the end of the URL once you are sent there, or it will error.
#If you need access to your Heroku logs type:
heroku logs --tail
#To run your server locally
rails server
#browse to http://localhost:3000 to see your site on your local machine
#When you make changes to your code, every time you do something major (or almost anything really) you should commit to git. You don't always have to push to Github, but its a good idea
git add .
git commit -m "Here is what I did"
git push origin master
#To push code to Heroku and deplpoy
git add .
git commit -m "Here is what I did"
git push heroku master
#If you have made database changes, you'll have to run the 'rake' thing again
#For local:
rake db:migrate
#for Heroku:
heroku run rake db:migrate
#If Heroku is being strange and you made major changes, try:
heroku restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment