« Tom

Deploy a Hobo app on Heroku

Posted by Tom.

This recipe will take you through the process of getting a Hobo app deployed on Heroku Garden. We’ll work through creating a brand new app and getting it deployed, and then discuss how you would use the same approach with an existing app.

Prerequisites: you will need git and the herokugarden gem (gem install herokugarden)

Deploying a new Hobo app with Heroku Garden

1. Log in to Heroku Garden and create the new app. Rather annoyingly, Heroku doesn’t prompt you for the app name, so we’ll start by renaming the app. Click on your email address down in the Heroku bar on the right. That will take you back to “My Apps”. Then click “Settings” for the new app, and you’ll be able to rename it. Keep the browser open on that page.

For the recipe we’ll assume you’ve called it hoboapp, but remember that all Heroku apps live in one global namespace, so you’ll need to use your own name. Use your name wherever you see hoboapp.

2. Grab a local clone of the app:

$ herokugarden clone hoboapp
$ cd hoboapp

3. Switch to Rails 2.2.2. By default a new Heroku Garden app will be configured to use Rails 2.1, but Hobo needs Rails 2.2.2. Edit config/environment.rb and change the RAILS_GEM_VERSION to:

RAILS_GEM_VERSION = '2.2.2'

(Should be the first line of the file).

4. Add Hobo as a git submodule. This adds an extra step to making things work with Heroku, but Hobo is a moving target and being able to keep up to date with changes is critical. Having Hobo as a submodule makes this much easier.

$ git submodule add git://github.com/tablatom/hobo.git vendor/plugins/hobo

When we push our changes, Heroku will not grab the Submodule for us. The easiest way to fix that is to write a simple Rake task that will update any submodules in the app.

5. Create a rake task to do the submodule update.. Create a file lib/tasks/git_submodules.rake containing the following:

task :git_submodules do
  puts `git submodule init 2>&1`
  puts `git submodule update 2>&1`
end

6. “Hoboize” the blank Rails app. We’ll run the standard Hobo generators:

ruby script/generate hobo --add-routes
ruby script/generate hobo_rapid --import-tags
ruby script/generate hobo_user_model user
ruby script/generate hobo_user_controller user
ruby script/generate hobo_front_controller front --delete-index --add-routes

7. Run the migration generator to create the initial migration, which will just create the users table.

ruby script/generate hobo_migration

(Chose the ‘g’ or ‘m’ option)

8. Commit the code into the repo:

$ git add .
$ git commit -am "Hoboize the app"

9. push your code up to Heroku. Note that you will get an error about the Hobo gem not being available. That’s OK.

$ git push

10. Run the rake task that we defined above. The heroku gem allows us to run remote rake tasks:

$ herokugarden rake hoboapp git_submodules

It may take a while, but you should eventually see the normal output from the git submodule init and git submodule update commands.

11. Run migrations. We can use the herokugarden remote rake tasks again:

herokugarden rake hoboapp db:migrate

12. run Hobo’s taglib generators. Return to your terminal and run:

$ herokugarden rake hoboapp hobo:generate_taglibs

13. Install will_paginate. In the file browser on Heroku’s edit page, expand the ‘vendor’ folder and click “Gems and plugins”. Select “Available” instead of “Installed” from the menu, and search for will_paginate. I found that installing the gem version did not work, so install the plugin version.

You should now be able to click the “view” link in the top right of the Heroku editor and see your deployed app up and running.

Deploying an existing app.

As far as I know, Heroku want to host the git repo for you, so again we’ll need to create a blank Heroku app. Perform steps 1 to 4 exactly as above.

Steps 6 and 7 should not be necessary if we already have a running app. We want instead to copy our existing code into this repo, overwriting the files that are already there, but make sure you don’t overwrite the .git directory. Also, if your app already has Hobo in vendor/plugins, don’t copy that over, as you’ve just created a submodule for Hobo.

Having copied the files in we want to commit them to git, push them up to Heroku and so on. In other words, perform steps 7 to 13 exactly as above.

User contributed notes

  • On November 13, 2008 Owen said:

    Thanks, Tom!

    Got my first Hobo Application shell up at Heroku!

    http://screencast.com/t/LMpPO9eie

    Now got to fill it in!

  • On November 14, 2008 Owen said:

    Bart,

    I'll get back in and try to fill in some models...

    -owen
  • On November 14, 2008 Owen said:

    We now have deployed a new and existing app on Heroku…looking good!

    Installed “will_paginate” as a plugin…that seems to work. http://screencast.com/t/sY3AxnTE

  • On November 15, 2008 Bart said:

    Great, that worked for me too, just needed to install the plugin locally with:
    ruby script/plugin install git://github.com/mislav/will_paginate.git
    and then push it to Heroku.. easy!

    Trying to install the plugin using the Heroku web interface however did not work.
  • On November 19, 2008 nigelthorne said:

    Shouldn't the task read

    task :git_submodules do
    system 'git submodule init 2>&1'
    system 'git submodule update 2>&1'
    end

    not

    task :git_submodules do
    puts `git submodule init 2>&1`
    puts `git submodule update 2>&1`
    end

    ?
    By the way... thanks for writing this tutorial.
    I had to install will_paginate too.

    I also had to do
    rake tmp:clear
    at several point to get the server to work.
  • On March 19, 2009 flash said:

    Thanks so much, Tom!

    Been trying for a year! Now I can use Hobo.
  • On April 27, 2009 oillio said:

    The new Heroku.com setup is much easier to use than HerokuGarden.
    To get rolling over there, take your regular old Hobo app and add a file at the app’s root named ‘.gems’
    In .gems add the following line:
    hobo –source gems.rubyforge.org –source gems.github.com

    This will command Heroku to install hobo and it’s dependencies. That’s it.
    Then run through the Heroku quick start guide.

    Easy.

  • On June 04, 2009 petef said:

    Hmm, it's not going quite so smoothly for me, when I push I get:

    > -----> Heroku receiving push
    >
    > -----> Installing gem will_paginate from http://gems.rubyforge.org
    > Successfully installed will_paginate-2.2.2
    > 1 gem installed
    >
    > -----> Installing gem hobo from http://gems.rubyforge.org
    > ERROR: Error installing hobo:
    > hobo requires mislav-will_paginate (>= 2.2.1, runtime)

    Is this because will_paginate has come from rubyforge and hobo is looking specifically for the github version?
  • On September 09, 2009 kevinpfromnm said:

    Probably, this is what I’ve got:

    mislav-will_paginate -s http://gems.github.com

    I’m not using the hobo gem but edge hobo.

    I wrote a new recipe. Since heroku doesn’t support submodules anymore, you’re limited to gem install or cloning edge hobo and removing the .git folders.

  • On December 29, 2009 andyw8 said:

    I’ve posted an up-to-date tutorial showing how to use the Hobo gem on Heroku:

    http://andywaite.com/2009/12/28/deploying-a-hobo-app-to-heroku

  • On June 15, 2010 spicerunner said:

    Slightly different approach, using Rails 2.3.8 and the Bamboo stack.

    http://www.kiwiluv.com/techblog/?p=560