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])
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论