Archive for February, 2012
Creating a staging environment on Heroku
Posted by John in Ruby and Rails on February 21, 2012
If you’re hosting your app on Heroku (possibly even if you aren’t) it is a good idea to create a staging environment also. Heroku has docs on this but the short version for a new app is:
heroku create staging-app-name --stack cedar --remote staging(if the app is already on Heroku, just add the remote:git remote add staging git-url-on-heroku)git push staging masterheroku rake db:migrate --remote stagingheroku rake db:seed --remote staging
Hopefully you have a staging environment set in config/environments/staging.rb so:
heroku config:add RAKE_ENV=staging --remote stagingheroku config:add RAILS_ENV=staging --remote staging
If you want to push a different branch to staging such as develop:
git push staging develop:master
Once staging is set, create the production app in the same way:
heroku create app-name --stack cedar --remote productiongit push production masterheroku rake db:migrate --remote productionheroku rake db:seed --remote production
Heroku error with conditional rb-fsevent gem
Posted by John in Ruby and Rails on February 16, 2012
Using the guard gem to run tests etc in your Rails app normally requires some form of file system monitoring.
The monitoring will be OS dependant and rb-fsevent is the gem for OSX. This can be added to the Gemfile conditionally with:
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
Unfortunately when you next push to Heroku you are likely to get an error along the lines of:
This is due to Heroku not allowing conditions in the Gemfile, even in the dev group.
The alternative is to put the gem in it’s own group:
And on non Mac systems run bundle install --without darwin (this only needs to be run once, the without setting is remembered for future bundle installs). Then for Heroku run heroku config:add BUNDLE_WITHOUT="development test darwin"
Don’t forget to add –remote remote_name if you are pushing to a remote other than heroku (e.g. heroku config:add BUNDLE_WITHOUT="development test darwin" --remote staging) and don’t forget to merge your amended Gemfile into master before running git push heroku master.
Use multiple accounts with Heroku
https://github.com/ddollar/heroku-accounts is a plugin for Heroku to allow you to use multiple accounts, e.g. work and personal.
To install: heroku plugins:install git://github.com/ddollar/heroku-accounts.git
Then set up each account:
heroku accounts:add personal --autoheroku accounts:add work --auto
Set your default: heroku accounts:default personal
Then to switch account for an app: heroku accounts:set work