使用每个块打印所有Zombie的名称

bob*_*bob 2 for-loop ruby-on-rails zombie-process

我正在尝试在代码学校做"僵尸的轨道"课程,但我坚持这个:

http://railsforzombies.org/levels/3/challenges/3

关于本课程令人沮丧的是,您无法优化您的答案,因为您没有看到错误解决方案的返回值.

无论如何,数据库看起来像这样:

id  name    graveyard
1   Ash     Glen Haven Memorial Cemetary
2   Bob     Chapel Hill Cemetary
3   Jim     My Fathers Basement
Run Code Online (Sandbox Code Playgroud)

挑战是"使用每个块来打印所有僵尸的名字"

我的解决方案是:<%zombies.each do | z | put z.name end
%>

这失败了,但我没有看到它是如何失败的,所以我无法改进它.解决办法是什么?

Zab*_*bba 8

试试这个:

<% zombies.each do |z| %>
  #note the equal-to sign below. this means that the text will be sent as output
  <%= z.name %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

笔记:

  • puts 用于将文本输出到控制台
  • <%= %> 是在ERB模板中输出文本的方法