开发者

Don't know how use 'serialize' method in rails

开发者 https://www.devze.com 2023-01-16 15:13 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消