Backport Rails 4.0.10 compatability to 4-0-stable branch

This fix is already present in master, but only for Rails 4.1 and up.
Merge pull request #463 from vincentwoo/patch-1

Backport Rails 4.0.10 compatability to 4-0-stable branch