---
title: "comparison of Fixnum with nil failed"
author: "muyu"
date: "2008-11-28T20:59:39Z"
tags: []
slug: "comparison-of-fixnum-with-nil-failed"
draft: false
lastmod: "2008-11-28T21:49:32Z"
id: 282714
url: "https://muyu.iteye.com/blog/282714"
---

```
  def validate
    errors.add(:score, '您的积分不够') if (!self.cur_ask_score.nil?) && (self.score > self.cur_ask_score)
  end
```

 

 这是在model里的验证。

 

刚开始，我写成了

 

```
  def validate
    errors.add(:score, '您的积分不够') if self.score > self.cur_ask_score
  end
```

 

 结果，程序出现如下错误：

 

 

```
comparison of Fixnum with nil failed
```

  

就在刚才，我又碰到一个怪异的问题------通常认为，保存成功的操作却怎么也不管用！

 

这类问题，一般是model验证失败导致的！