如何在 Rails 中拥有无名的 YAML 固定装置?

发布于 2024-08-22 21:50:32 字数 256 浏览 3 评论 0原文

假设我们有。

 apple:
    name: apple

  orange:
    name: orange

  grape:
    name: grape

这能变成下面的东西吗?

    name: apple

    name: orange

    name: grape

因为我有大约 25 个项目,手动命名它们确实是一项毫无价值的工作。

Let's say we have.

 apple:
    name: apple

  orange:
    name: orange

  grape:
    name: grape

Can this turn into something below?

    name: apple

    name: orange

    name: grape

Because I have like 25 items, manually name them is really a valueless job.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2024-08-29 21:50:32

不,您不能,还因为这不是有效的 YML 语法。
每个固定元素必须属于一个反映 YAML 节点名称的名称。

但是,您可以使用 Ruby 生成名称。

<% %w(apple orange grape).each do |fruit| %>
<%= fruit %>:
    name: <%= fruit %>
<% end %>

No, you can't, also because this is not a valid YML syntax.
Each fixture element must belong to a name which reflects the YAML node name.

However, you can generate the names with Ruby.

<% %w(apple orange grape).each do |fruit| %>
<%= fruit %>:
    name: <%= fruit %>
<% end %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文