Updated version, now compatible with Rails 4 final