Your interface to Heroku is essentially a Git branch. The Heroku gem does some work through their API, but within your Git repository, it's just a new remote branch.
heroku create yourapp # production
git br -D heroku # delete the default branch
heroku create staging-yourapp # staging
git br -D heroku # delete the default branch
Once you set up multiple applications on Heroku, you should be able to configure your Git repository like this:
git remote add staging git@heroku.com:staging-yourapp.git
git push origin staging
git remote add production git@heroku.com:yourapp.git
git push origin production
I usually work in a 'working' branch, and use Github for my master.
Assuming that's the case for you, your deploy workflow would probably look something like:
git co -b working
# do some work
# push to github:
git co master
git merge working
git push
# push to staging:
git co staging
git merge master
git push origin staging
# push to production
git co production
git merge master
git push origin production
A key part of the original question is about linking up the staging app to a subdomain (dev.myapp.com) of the main app (www.myapp.com). This hasn't been addressed in any of the answers.
Step 1: Configure both production ('myapp') and staging ('staging-myapp') versions of your app as is indicated in the answer by Luke Bayes
Step 2: In your domain management system (e.g. GoDaddy):
Create a CNAME record: dev.myapp.com
that points to: proxy.heroku.com
Step 3: Configure Heroku to route dev.myapp.com to staging-myapp:
This will create named remote repos for each app, which you can see in .git/config.
You can now use either the --app or --remote switches to target a particular app:
$ heroku info --app myapp-staging
$ heroku info --remote staging
Set Rails environments
For Rails apps, Heroku defaults to the "production" environment. If you want your staging app to run in a staging environment, create the environment in your project and set the corresponding RAILS_ENV and RAKE_ENV environment variables on the app: