Create Rails app with RVM to set ruby version and gemset from directory

I’ve always chosen which version and gemset to use with RVM by writing in the console before entering an application. I today found a nice little trick to make RVM understand this itself whenever you enter the directory of your new Rails app. So here goes ;)

mkdir mynewrailsapp
cd mynewrailsapp
rvm use ruby-2.0.0@mynewrailsapp --ruby-version --create
gem install rails
rails new .

It will now create two files: .ruby-version and .ruby-version and whenever you enter this directory RVM will switch automatically.

Sweet, right?