-1

我有一个这样的 erb 模板,我想直接将哈希对象转储到其中。

# test.yml.erb
---
name: <%= name || "bat" %>
director_uuid: <%= uuid %>

release:
  name: bat
  version: <%= release.name || "latest" %>

<%= YAML.dump(compilation) %>

update:
  canaries: 1
  canary_watch_time: 3000-90000

<%= YAML.dump(network)%>

但我ERB.new(test.yml.erb).result(binding)只是得到这个:# test.yml --- name: bat director_uuid: uuid

release:
  name: bat
  version: lastest

---
compliaton:
  workers: 1
  network: default    

update:
  canaries: 1
  canary_watch_time: 3000-90000

---
networks:
  name: default

有没有办法删除不需要的---?任何帮助,将不胜感激

4

1 回答 1

2

只需从 YAML 的转储输出中删除它:

<%= YAML.dump(compilation).sub(/.*?\n/, '') %>
于 2013-03-28T08:36:44.900 回答