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??? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Dec-18 19:22 UTC
Re: exists? && new? undefined in ActiveRecord::Base???
On 18 Dec 2008, at 19:10, Tim McIntyre wrote:> > 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???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> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 Dec 2008, at 19:10, Tim McIntyre wrote: > > > > > > > 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??? > > 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---