Fixed query builder to work with Rails 4.1