Re: "RuntimeError: Called id for nil" when saving

Jamis Buck
Fri, 19 Aug 2005 21:07:05 -0000

On Aug 19, 2005, at 2:45 PM, Eric Goodwin wrote:

> Hey,
> I''m having an error when I try to save anything. Here is the
output
> from the console. Anyone know why this would be happeing.
>
> >> asset = Assetstatus.find(1)
> => #<Assetstatus:0x3bd3bf0
@attributes={"title"=>"Not Started",
> "id"=>"1", "deleted"=>nil}>
> >> asset.deleted = 0
> => 0
> >> asset.save
> RuntimeError: Called id for nil, which would mistakenly be 4 -- if
> you really wanted the id of nil
> , use object_id
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> usermonitor.rb:23:in `update''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/base.rb:1139:in
> `create_or_update_without_callbacks''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/callbacks.rb:249
> :in `create_or_update''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/base.rb:965:in `
> save_without_validation''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/validations.rb:6
> 50:in `save_without_transactions''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/transactions.rb:
> 128:in `save''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/transactions.rb:
> 128:in `transaction''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/transactions.rb:
> 93:in `transaction''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/transactions.rb:
> 120:in `transaction''
>        from c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
> active_record/transactions.rb:
> 128:in `save''
>        from (irb):13
>        from :0

I''m not sure what ''usermonitor.rb'' is... it looks
like it is in the
activerecord directory, but I don''t believe it''s a part of
ActiveRecord itself. Is it something you added, perchance? What does
line 23 of that file look like?

- Jamis