Fix deprecations

Fix deprecations under rails 4.0, and this is also necessary for rails 4.1 upgrade.