
Support for [Grails on Heroku was recently announced][1] and I'd like to walk you through the steps to create a simple Grails app and then deploy it on the cloud with Heroku. Before you get started [install Grails 2.0.0][2], [install the Heroku toolbelt][3], [install git][4], and [signup for a Heroku.com account][5]. Don't worry, you won't need to enter a credit card to give this a try because Heroku gives you [750 free dyno hours per application, per month][6]. (Wondering what a "dyno" is? Check out: [How Heroku Works][7]) Let's get started.

**Step 1)** Create the app:

```bash
grails create-app grailbars
```

You'll need to do the rest of this from inside the newly created "grailbars" directory:

```bash
cd grailbars
```

**Step 2)** Create a new domain object:

```bash
grails create-domain-class com.jamesward.grailbars.Bar
```

**Step 3)** Edit the _grails-app/domain/com/jamesward/grailbars/Bar.groovy_ file so it looks like:

```groovy
package com.jamesward.grailbars

class Bar {
    String name
}
```

**Step 4)** Generate the controllers and views for the Bar model:

```bash
grails generate-all com.jamesward.grailbars.Bar
```

**Step 5)** Run the app locally to test it out:

```bash
grails run-app
```

Now open it in your browser: <http://localhost:8080/grailbars>

**Step 6)** Heroku provides a free Postgres database that we want our application to use. The easiest way to do that is using the [Heroku Grails Plugin][8]. Install the "heroku" and the "cloud-support" plugins:

```bash
grails install-plugin heroku
grails install-plugin cloud-support
```

Then edit the _grails-app/conf/BuildConfig.groovy_ file and add the Postgres JDBC driver as a dependency by adding the following to the "dependencies" section:

```groovy
runtime 'postgresql:postgresql:9.1-901-1.jdbc4'
```

**Step 7)** Setup a git repository for the project which will be used for transferring the files to Heroku:

```bash
grails integrate-with --git
git init
git add application.properties grails-app test web-app
git commit -m init
```

**Step 8)** Login with the Heroku CLI:

```bash
heroku login
```

**Step 9)** Ceate a new application using the "cedar" stack:

```bash
heroku create -s cedar
```

**Step 10)** Upload your application to Heroku:

```bash
git push heroku master
```

Now open the application running on Heroku in your browser (the URL was in the "heroku create" and "git push" output). Verify that it works. Awesome! You just built a Grails app and deployed it on the Cloud with Heroku! For more details on using Grails on Heroku, visit the [Heroku Dev Center][9] and checkout the [Heroku Grails Plugin documentation][8]. Let me know if you have any questions. Thanks!

 [1]: http://blog.heroku.com/archives/2011/12/15/grails/
 [2]: http://grails.org/
 [3]: http://toolbelt.heroku.com
 [4]: http://git-scm.com/
 [5]: http://heroku.com/signup
 [6]: http://devcenter.heroku.com/articles/how-much-does-a-dyno-cost
 [7]: http://www.heroku.com/how
 [8]: http://grails.org/plugin/heroku
 [9]: http://devcenter.heroku.com/articles/grails
