Rails4

This is a bit of a refactoring from @afhammad's Pull Request #16 
- Maintains backward compatability