Bug fix for klass nil

Ready to merge on rails 4.