ruby rail understanding sql