# Accessing created\_on causes type error

**URL:** <https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893>\
**Category:** Rails\
**Created:** [April 26, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893 "2006-04-26T23:28:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kenneth\_D](https://www.ruby-forum.com/u/Kenneth_D)\
**Post date:** [April 26, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893/1 "2006-04-26T23:28:21Z")

</div>

I assume that this is some newbie stupidity, but I haven’t found my  
way around this problem. I have an ActiveRecord object fetched  
from the database, and I need to evaluate the contents of the  
updated\_on field. However, _any_ attempt to access that data in the  
program results in a TypeError with the message ‘no implicit conversion  
from nil to integer’.

cust = Customer.find(:first, :conditions =\> [“custid = ?”, custid]  
if cust.updated\_on.nil?  
…never gets here  
end

Any help would be much appreciated

Ken

–

I use the words you taught me. If they don’t mean anything any more,  
teach me others. Or let me be silent.  
Samuel Beckett (Clov, Endgame)

---

<div class="post-metadata">

**Author:** ![Kenneth\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kenneth\_D](https://www.ruby-forum.com/u/Kenneth_D)\
**Post date:** [April 27, 2006, 1:28am UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893/2 "2006-04-27T01:28:14Z")

</div>

Kenneth D. wrote:

> However, _any_ attempt to access that data in the  
> program results in a TypeError with the message ‘no implicit conversion  
> from nil to integer’.
> 
> cust = Customer.find(:first, :conditions =\> [“custid = ?”, custid]  
> if cust.updated\_on.nil?  
> …never gets here  
> end

Hi Kenneth,

Is cust nil? Is custid nil? Try running the code with script/console.

Dan

---

<div class="post-metadata">

**Author:** ![Kenneth\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kenneth\_D](https://www.ruby-forum.com/u/Kenneth_D)\
**Post date:** [April 27, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893/3 "2006-04-27T18:10:31Z")

</div>

Quoth Dan Perez (removed\_email\_address@domain.invalid):

> > 
> 
> Hi Kenneth,
> 
> Is cust nil? Is custid nil? Try running the code with script/console.
> 
> Dan

No, custid was not nil. FWIW, this is part of a support script which  
does backend things for a rails project, so was not being run under  
rails. As it turns out, the problem I have above _only_ happens  
when I am running the script in the debugger. It’s very strange.  
cust is a fully initialized object. I can access values in the  
debugger,  
including the updated\_on field. But when the next line of code tests  
to see if updated\_on is nil, all hell breaks loose.

## Ken

I use the words you taught me. If they don’t mean anything any more,  
teach me others. Or let me be silent.  
Samuel Beckett (Clov, Endgame)

---

<div class="post-metadata">

**Author:** ![Kenneth\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kenneth\_D](https://www.ruby-forum.com/u/Kenneth_D)\
**Post date:** [April 27, 2006, 10:15pm UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893/4 "2006-04-27T22:15:09Z")

</div>

Kenneth D. wrote:

> end

1. Are you sure that there is a customer found?
2. If there is a customer found, what does the database say its  
updated\_on value should be?
3. What db are you using, and what is the type of updated\_on in the db?
4. What’s the stack trace?

–

Ray

---

<div class="post-metadata">

**Author:** ![Kenneth\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kenneth\_D](https://www.ruby-forum.com/u/Kenneth_D)\
**Post date:** [April 27, 2006, 6:38pm UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893/5 "2006-04-27T18:38:10Z")

</div>

> No, custid was not nil. FWIW, this is part of a support script which  
> does backend things for a rails project, so was not being run under  
> rails. As it turns out, the problem I have above _only_ happens  
> when I am running the script in the debugger. It’s very strange.  
> cust is a fully initialized object. I can access values in the  
> debugger,  
> including the updated\_on field. But when the next line of code tests  
> to see if updated\_on is nil, all hell breaks loose.

Weird. I assume you’re not missing the ‘)’ in your actual code, just  
the post, right?

Dan

---

<div class="post-metadata">

**Author:** ![Kenneth\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kenneth\_D](https://www.ruby-forum.com/u/Kenneth_D)\
**Post date:** [May 3, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/accessing-created-on-causes-type-error/58893/6 "2006-05-03T18:58:05Z")

</div>

Quoth Ray B. (removed\_email\_address@domain.invalid):

> > if cust.updated\_on.nil?  
> > …never gets here  
> > end
> 
> 1. Are you sure that there is a customer found?

Yes.

> 1. If there is a customer found, what does the database say its  
> updated\_on value should be?

‘0000-00-00 00:00:00’. The cust object agrees, if I look at it in the  
debugger.

> 1. What db are you using, and what is the type of updated\_on in the db?

MySQL 5.0.17  
updated\_on timestamp NOT NULL default ‘0000-00-00 00:00:00’

> 1. What’s the stack trace?

Here’s debugger output including the stack trace:  
/usr/local/adm/accnt/script/customer.rb:112: webcust =  
WebCustomer.find(:first, :conditions =\> [“custid = ?”, self.custid])  
(rdb:1) n  
/usr/local/adm/accnt/script/customer.rb:113: if webcust.nil?  
(rdb:1) n  
/usr/local/adm/accnt/script/customer.rb:113: if webcust.nil?  
(rdb:1) n  
/usr/local/adm/accnt/script/customer.rb:131: if not  
webcust.updated\_on.nil?  
(rdb:1) n  
/usr/local/adm/accnt/script/customer.rb:131: if not  
webcust.updated\_on.nil?  
(rdb:1)  
n  
/pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/abstract/schema\_definitions.rb:112:  
`no implicit conversion from nil to integer' (TypeError) from /pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:278:in`each’  
from  
/pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:278:in  
`columns' from /pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:734:in`columns’  
from  
/pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:742:in  
`columns_hash' from /pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1532:in`define\_read\_methods’  
from  
/pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1482:in  
`method_missing' from /usr/local/adm/accnt/script/customer.rb:131:in`save\_to\_sql’  
from customer\_upload.rb:17  
from customer\_upload.rb:13:in `each\_line’  
from customer\_upload.rb:13  
/pkg/ruby-1.8.2/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/abstract/schema\_definitions.rb:112:  
Time.send(Base.default\_timezone, \*time\_array) rescue nil

The code runs fine _outside_ of the debugger.

Ken

–

I use the words you taught me. If they don’t mean anything any more,  
teach me others. Or let me be silent.  
Samuel Beckett (Clov, Endgame)
