开发者

How to have nameless YAML fixtures in Rails?

开发者 https://www.devze.com 2022-12-21 08:49 出处:网络
Let\'s say we have. apple: name: apple orange: name: orange grape: name: grape Can this turn into s开发者_如何学Comething below?

Let's say we have.

 apple:
    name: apple

  orange:
    name: orange

  grape:
    name: grape

Can this turn into s开发者_如何学Comething below?

    name: apple

    name: orange

    name: grape

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


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 %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号