Posts Tagged Heroku
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
Rails 3.1 on Heroku, TLDR Version
Posted by John in Ruby and Rails on December 13, 2011
Create the app
- If not installed, install PostgreSQL
rails new app_name -T -d=postgresqlcd app_name/rvm --create --rvmrc 1.9.2@app_namervm rvmrc trust- Edit .Gemfile
bundle installcreateuser -P -S -R -d app_name(no to ‘Superuser’ and ‘Create roles’, yes to ‘Create databases’)rake db:create- Create procfile in app root.
foreman startand check http://0.0.0.0:5000/
Push to Github
- Edit .gitignore
git flow initgit add .git commit -m 'Project skeleton'- Create app_name on Github
git remote add origin git@github.com:JohnPlummer/app_name.gitgit push -u origin developgit push -u origin master
Push to Heroku
heroku create app-name --stack cedargit flow release start '0.0.1'git flow release finish '0.0.1'git push --allgit push heroku masterheroku run rake db:seedheroku open
Installing Postgresql and pgAdmin
Posted by John in Ruby and Rails on December 6, 2011
The default database for Heroku is PostgreSQL and, while you could use SQLite for development and Postgres for production, there are some inconsistencies between the two. Ideally you would use the same version of the database server but currently Heroku uses version 9 for dedicated databases and 8.3 for shared databases and seem to recommend you install the latest version for development.
Install Postgres with Homebrew with brew install postgresql and follow the instructions after the install to initialise a database.
initdb /usr/local/var/postgres
The database server can be set to start at login with
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.1/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
But I prefer to add aliases to .bashrc to start and stop the server:
alias pgs='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias pgq='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
Postgres can be managed with the command line utility psql but, as much as I like the command line, I don’t really want to have to write SQL to edit or remove a user role. PgAdmin is a free GUI for Postgres management. Once installed, ensure the Postgres server is running then run pgAdmin and connect to the server.
In the server properties add a name for the connection and add your login as the username.

pgAdmin provides the management tools you would expect.

Rails, Compass, HTML5 Boilerplate and Heroku
Posted by John in Ruby and Rails on April 14, 2011
Overview
HTML5 provides some great functionality but also, potentially, some headaches. HTML5 Boilerplate is a template which aims to solve the various cross-browser differences.
There is a gem to use HTML5 Boilerplate in a rails app which uses Compass to build the CSS. Using Compass on Heroku requires a small workaround as Heroku limits where an app can write to.
Setup
For a new Rails App: Follow the process in prior post on setting up a new project.
After the rspec and cucumber installs run
When asked, select yes for change of SASS location but no to change of CSS location
Carry on through prior post (but don’t install jquery as that is part of the HTML5 Boilerplate)
Create a home controller script
Delete the /public/index.html and the app/views/layouts/application.html.erb files
Set the root in the config/routes.rb
Fix the annoying Rails 3.0.5 bug by amending the javascript expansions line in config/application.rb to
The app should now run locally using hml5-boilerplate, compass, and haml.
Heroku
But not on Heroku, to run on Heroku the css files need to be written to a tmp directory as that is the only folder the app can write to.
In config/compass.rb change the css_dir line to
Change config/initializers/compass.rb to
This should allow the app to run locally and hosted on Heroku.
To push to Heroku follow these instructions.
In summary, once you have your SSH keys set up: