Updated to work correctly with Rails 4