Fix compatibility with Rails 4.1.0

The changes should be backwards compatible, but have not yet been tested
with older versions of Rails.