[英]Unable to see attr_accessors when transforming object to JSON
I have a class with attr_accessors. 我有一个attr_accessors类。 When I want to create a JSON string of my object, my attr_accessors are not listed, only attributes created with mongo.
当我要创建对象的JSON字符串时,未列出我的attr_accessors,仅列出了使用mongo创建的属性。
class Weblink < Media
field :title, :type => String
field :url, :type => String
attachment :image
attr_accessor :images, :domain_name, :image_width, :image_height
end
The generated JSON 生成的JSON
{"_id":"4e3ab9895d156dae63000001","_type":"Weblink","description":"Some description","title":"Some title","url":"http://some_url.com"}
I would like to have for exemple, my "images" attributes included. 例如,我想包含“图像”属性。
Any suggestions ? 有什么建议么 ?
尝试:
weblink.to_json(:methods=>[:images, :domain_name, :image_width, :image_height])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.