Forum: Ruby on Rails Doesn't "find" call initialize?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
r00by n00by (Guest)
on 2006-01-04 17:05
class Item < ActiveRecord::Base

   def initialize(*args)
      @x = 5


   def print_x
      puts @x

item_new =
item_new.print_x   # output: 5

item_find = Item.find(1) # this record is in the database
item_find.print_x  # output: nil

I thought the output would be 5 in both cases, since Item.find returns a
new object of Item and so Item.initialize would be called
This topic is locked and can not be replied to.