Don't know how use 'serialize' method in rails
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 'NoMetho开发者_如何学PythondError' 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 ?
"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.
精彩评论