# X is not a number error?

**URL:** <https://www.ruby-forum.com/t/x-is-not-a-number-error/138072>\
**Category:** Rails\
**Created:** [May 20, 2008, 12:25am UTC](https://www.ruby-forum.com/t/x-is-not-a-number-error/138072 "2008-05-20T00:25:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [May 20, 2008, 12:25am UTC](https://www.ruby-forum.com/t/x-is-not-a-number-error/138072/1 "2008-05-20T00:25:31Z")

</div>

I may be overlooking something really obvious here but I’m not getting  
it. I have a Category model. Categories can have sub categories and  
parent categories, but when a category doesn’t have a parent category,  
its “parent\_categoryid” field is set to null. As far as I know, what I  
am doing here has been working in the past because there are many  
categories in my categories table with null parent\_categoryid fields.  
For some reason, when I do:

c = Category.find(12345)  
c.save

It returns false when c.parent\_categoryid = NULL, and c.errors says  
#\<ActiveRecord::Errors:0xb708ce08 @errors={“parent\_categoryid”=\>[“is  
not a number”]}, …

In the DB on the exact same record, I can do:

update categories set parent\_categoryid = NULL where id = 12345;

And it works just fine. Any ideas why I’m getting this problem? I am  
running Rails v1.2.6, PostgreSQL 8.2.4, and Ruby 1.8.6. The relevant  
database constraints are:

```
                               Table "public.categories"
  Column | Type |

```

Modifiers  
-------------------±--------  
±-------------------------------------------------------------------------  
id | integer | not null default  
nextval(‘categories\_id\_seq’::regclass)  
parent\_categoryid | integer |  
…  
Indexes:  
“categories\_parent\_categoryid” btree (parent\_categoryid)  
Foreign-key constraints:  
“$1” FOREIGN KEY (parent\_categoryid) REFERENCES categories(id) ON  
DELETE CASCADE

Thanks for any help you can offer.

Matt

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [May 20, 2008, 12:29am UTC](https://www.ruby-forum.com/t/x-is-not-a-number-error/138072/2 "2008-05-20T00:29:41Z")

</div>

Naturally, I figure it out 5 minutes after I post the message. Someone  
slipped a “validates\_numericality\_of :parent\_categoryid” in the  
Category model without my knowing.

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [May 20, 2008, 12:30am UTC](https://www.ruby-forum.com/t/x-is-not-a-number-error/138072/3 "2008-05-20T00:30:16Z")

</div>

On 19 May 2008, at 23:24, Matt W. wrote:

> c.save
> 
> It returns false when c.parent\_categoryid = NULL, and c.errors says  
> #\<ActiveRecord::Errors:0xb708ce08 @errors={“parent\_categoryid”=\>[“is  
> not a number”]}, …

Sounds like you’ve got a (ActiveRecord) validation on that column.

Fred
