开发者

Unable to see attr_accessors when transforming object to JSON

I have a class with attr_accessors. When I want to create a JSON string of my object, my attr_accessors are not listed, only attributes created with mongo.

class Weblink < Media
  field :title, :type => 开发者_如何学JAVAString
  field :url, :type   => String
  attachment :image

  attr_accessor :images, :domain_name, :image_width, :image_height
end

The generated 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 ?


try:

weblink.to_json(:methods=>[:images, :domain_name, :image_width, :image_height])
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜