我正在尝试在厨师模板中渲染一个 yaml 对象,它工作正常,但正如我们所知,在 yaml 空间中也很重要,因此它正在创建新属性。
collection: <%= @collection.to_hash.to_yaml %>
其中collection是一个json对象
collection = { "name": "col1", "nested": { "nKey": 1 } }
预期结果是
collection:
name: col1
nested:
nKey: 1
得到结果
collection: ---
name: col1
nested: !ruby/hash:Mash #nested is not part of collection.
nKey: 1
其次,有什么方法可以从 to_yaml 函数中删除 types( !ruby/hash:Mash
)吗?---