This is a quick step-by-step guide for how I've been getting quick proof-of-concept rails apps up and running in 2016. Mostly for my own reference. Feedback welcome :)
It’s just easier... Who needs to mess with devops in 2016?
- Create an account at heroku.com
- Install the Heroku command line tools on your machine
- Install Ruby (with Rbenv?)
- Install rails (with brew? or just gem install rails?) ... I can't remember
- Install postgress
brew install postgres
Your stuff is open source right? No? Why not?
- Visit github.com, login, and make a new repo.
- Select the Rails .gitignore template
- Return to your local machine and clone the repo into a folder there.
- Clone it locally and setup rails
git clone [git_repo_url]
#use postgres for Heroku
rails new [git_repo_name] --database=postgresql
#create a new heroku app from here
heroku create [app_name]
Add a few gems
#so you can use "heroku local"
gem 'puma'
# use slim. Kuz.
gem "slim-rails"
- Edit your
.gitignore
file to include your "secrets" (heroku needs these)
#config/initializers/secret_token.rb
#config/secrets.yml
- Add the files, commit, and push
#commit the files and the Gemfile.lock so we can deploy to heroku
git commit -am "first commit"
git push
-
Go back to heroku and open your app (maybe star it for convenient access)
-
Click “Deploy" and click the “GitHub” button
-
Connect to Github, find your repo and connect it to your app
-
Click automatic deploys if you want this.
-
Back to your code, update your
config/database.yml
like so:
default: &default
adapter: postgresql
pool: 5
encoding: unicode
timeout: 5000
development:
<<: *default
database: infoshare_dev
test: &test
<<: *default
database: infoshare_test
cucumber:
<<: *test
Make sure the database is running
#see how to start it (if you installed via brew)
brew info postgres
#Run whatever command the above recommends for your needs (e.g. run backround process or just keep it open in a shell)
#setup the databse
rake db:setup
rake db:migrate
Re-run bundler:
`bundle`
Create a Procfile
that looks like this:
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
Start herou locally
heroku local
- Write some tests, create some models, migrate your database, create some views, commit re-deploy... rinse and repeat.
Heroku won't do this for you automagically
NOT FINISHED
Add this to your Gemfile
#cucumber stuff
gem 'cucumber' #our testing framework
gem 'capybara' #nice DSL for talking to the browser in code.
gem 'selenium-webdriver' #usual, firefox driver
gem 'phantomjs'
gem 'poltergeist' #headless driver
gem 'rspec' #gives us a few nice methods like "page.should"
gem 'pry' # for command line debugging
gem 'capybara-screenshot'
gem 'firefox'
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
gem ‘database_cleaner'
Add these gems to your Gemfile
#for GOV.UK template
gem 'govuk_template'
#gem 'slimmer'
#for other GOV.UK elements
gem 'govuk_elements_rails'
#for sass mixins
gem 'govuk_frontend_toolkit'
You'll need to make a layouts/application.html.slim
file. See here.
- Register your app on the Google console (if that's what you're using)
- Get your client ID and secret
- use a .env file to hold these in environment variables
- Create a sessions controller with methods for new (basically redirects to the /auth URL), create (handles the callback), destroy (logs out),
- Create "signed_in?" method in
application_controller.rb
- Add this,
before_filter :check_login, :except=>[:welcome, :about]
to allow non-logged in folk to see the welcome & about pages. - Add the "check_login" method..
- Add a User model to hold name, email, is_admin? flag, etc.
- Add a user controller to perform CRUD operations on Users
##Troubleshooting
Make sure you’ve committed your secrets.yml file (check you .gitignore)