【问题标题】:How to have nameless YAML fixtures in Rails?如何在 Rails 中使用无名 YAML 固定装置?
【发布时间】:2010-02-22 16:21:06
【问题描述】:

假设我们有。

 apple:
    name: apple

  orange:
    name: orange

  grape:
    name: grape

这可以变成下面的东西吗?

    name: apple

    name: orange

    name: grape

因为我有 25 个项目,手动命名它们真的是一个没有价值的工作。

【问题讨论】:

    标签: ruby-on-rails fixtures


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 2010-10-05
      • 1970-01-01
      • 2011-03-27
      相关资源
      最近更新 更多