views:

34

answers:

1

i have a model called user

class User < ActiveRecord::Base
    serialize :friends
end

when running the console script and create a new object of User class

user = User.new
user.friends

i found a 'NoMethodError' should i write the serialize calling in another file? OR what should i do to make the friends array an attribute for the User instance ?

+4  A: 

"serialize friends" will create a serialized attribute on instances of your model.

So you need to refer to the instance:

user = User.new
user.friends

Note the lower case on the second line - you need to refer to the instance held in the user variable.

Toby Hede
sorry it was just a syntax error , actually i refer to the instance ,i have edited the original post .
saka