Reputation: 11
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 ?
Upvotes: 1
Views: 289
Reputation: 37143
"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.
Upvotes: 4