Upgraded the code to be used with Rails 3