Require active_record and refactor codes
Merge pull request #1 from rosylilly/refactor-nesting

Require active_record and refactor codes