#!/bin/bash
#Based on http://railsapps.github.com/installing-rails-3-1.html

cd ~

sudo apt-get -y install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev curl git-core

bash < <(curl -sk https://rvm.beginrescueend.com/install/rvm)

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

source .bash_profile

rvm install 1.9.2

rvm ruby-1.9.2-p180@rails31 --create --rvmrc

#update rake to 0.9.1 or newer
gem update rake

#update gems to 1.8.5 or newer..
gem update --system

gem install rails -v ">=3.1.0rc"

#create new rails app
rails new testapp

cd testapp
echo "gem 'therubyracer'" >> Gemfile

#should install execjs and therubyracer

bundle install

bundle exec rake -T

#run rails server
rails server