This table has a number of fields in it
id, created_at, tid, text
When I call lastrec.id, it works
When I call lastrec.created_at it gives me (undefined method
`created_at' for nil:NilClass)
I feel sure you must be mistaken somehow. Are you saying that if you
immediately follow the Capture.last line with
id = lastrec.id
created_at = lastrec.created_at
then the first line passes but you get the nil error on the second? I
will be surprised if that is the case (I am often surprised mind you).
One thing to try is to run that code in the ruby console.
Another is to use ruby-debug to break in after the Capture.last line
and examine the data at that point.
See the rails guide on debugging if you do not know about ruby-debug
(http://guides.rubyonrails.org/)
This table has a number of fields in it
id, created_at, tid, text
When I call lastrec.id, it works
When I call lastrec.created_at it gives me (undefined method
`created_at' for nil:NilClass)
I feel sure you must be mistaken somehow. Are you saying that if you
immediately follow the Capture.last line with
id = lastrec.id
created_at = lastrec.created_at
then the first line passes but you get the nil error on the second? I
will be surprised if that is the case (I am often surprised mind you).
One thing to try is to run that code in the ruby console.
Another is to use ruby-debug to break in after the Capture.last line
and examine the data at that point.
See the rails guide on debugging if you do not know about ruby-debug
(http://guides.rubyonrails.org/)
Colin
Hmm, does the id happen to be 4?
try:
puts nil.id
Last relative to what? If you mean: most recently created, try:
This table has a number of fields in it
id, created_at, tid, text
When I call lastrec.id, it works
When I call lastrec.created_at it gives me (undefined method
`created_at' for nil:NilClass)
I feel sure you must be mistaken somehow. Are you saying that if you
immediately follow the Capture.last line with
id = lastrec.id
created_at = lastrec.created_at
then the first line passes but you get the nil error on the second? I
will be surprised if that is the case (I am often surprised mind you).
One thing to try is to run that code in the ruby console.
Another is to use ruby-debug to break in after the Capture.last line
and examine the data at that point.
See the rails guide on debugging if you do not know about ruby-debug
(http://guides.rubyonrails.org/)
Colin
Hmm, does the id happen to be 4?
try:
> puts nil.id
I suspect you may well have hit the nail on the head, but why would
accessing nil.id in the code not generate the 'Called id for nil'
error? It does for me.