Forum: Ruby on Rails exists? && new? undefined in ActiveRecord::Base???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ab0b702e7fcc79bb7d2c6c67f64e1b4d?d=identicon&s=25 Tim McIntyre (Guest)
on 2008-12-18 20:11
(Received via mailing list)
I've got a trivial Order class:

class Order < ActiveRecord::Base
end

From the console:

Loading development environment (Rails 2.1.2)
>> o = Order.new
=> #<Order id: nil, partner_account_id: nil, delivery_status: nil,
payment_status: nil, stock_status: nil, complete: nil, admin_notes:
nil, partner_notes: nil, created_at: nil, updated_at: nil>
>> o.exists?
NoMethodError: undefined method `exists?' for #<Order:0x7ffd7eabcfd8>
        from /home/tim/projects/distrome/trunk/vendor/rails/
activerecord/lib/active_record/attribute_methods.rb:251:in
`method_missing'
        from (irb):2
>> o.new?
NoMethodError: undefined method `new?' for #<Order:0x7ffd7eabcfd8>
        from /home/tim/projects/distrome/trunk/vendor/rails/
activerecord/lib/active_record/attribute_methods.rb:251:in
`method_missing'
        from (irb):3

I've looked at the source and the methods are there.  How can this
be???
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-18 20:23
(Received via mailing list)
On 18 Dec 2008, at 19:10, Tim McIntyre wrote:

> => #<Order id: nil, partner_account_id: nil, delivery_status: nil,
>        from /home/tim/projects/distrome/trunk/vendor/rails/
> activerecord/lib/active_record/attribute_methods.rb:251:in
> `method_missing'
>        from (irb):3
>
> I've looked at the source and the methods are there.  How can this
> be???

exists? is a class method, so Order.exists?( id_or_conditions) (what
would o.exists? even mean?)

There is no new? method, although there is one on
ActiveResource::Base. Did you mean o.new_record?

Fred
Ab0b702e7fcc79bb7d2c6c67f64e1b4d?d=identicon&s=25 Tim McIntyre (Guest)
on 2008-12-18 20:34
(Received via mailing list)
my bad... thought I was loosing my mind there.... I was looking at the
code for ActiveResource::Base :-(

I was thinking that o.exists? would return whether the record exists
in the database, basically what new_record? does.

I knew it had to be something obvious... Sorry for the distraction and
thanks for setting me straight Fredrick!

Tim

On Dec 18, 11:22 am, Frederick Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.