Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以在 mongoid 中定义一个字段,但不能持久化吗?我需要 to_json 来包含该字段,并且使用 attr_accessor 和 after_initialize 来计算该值不会将其包含在 to_json 结果中。
通过操作 JSON 数组本身解决了这个问题,保留了 to_json 的大部分功能。
raw((c.to_json).insert(-2, ",\"url\":#{c.image_url.to_json}"))