Updated for Ruby 2 and Rails 4