为什么我的erb代码在教程没有时会产生时间戳?

时间:2017-01-17 20:25:22

标签: ruby-on-rails erb

我正在http://guides.rubyonrails.org/getting_started.html进行Rails入门指南,直到5.8的最后一部分。我的输出包含这个额外的行,我无法弄清楚它来自何处。有人可以帮我吗?

[#<Article id: 1, title: "Test", text: "tests", created_at: "2017-01-17 20:01:14", updated_at: "2017-01-17 20:01:14">]

教程代码 -

<h1>Listing articles</h1>

<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
    </tr>
  <% end %>
</table>

我的代码就是这个 -

<div>
<%= @articles.each do |article| %>
    <div>
      <div>Title:</div>
      <div><%= article.title %></div>
      <div>Text:</div>
      <div><%= article.text %></div>
      <div><%= link_to 'Show', article_path(article) %></div>
    </div>
<% end %>
</div>

2 个答案:

答案 0 :(得分:3)

删除=

<%= @articles.each do |article| %>

应该是

<% @articles.each do |article| %>

答案 1 :(得分:2)

只需将var studentsWhoPassed = context.Set<ClassEntity>() .Where(class => class.Tests.Any(test => test.Status == Status.Passed) && class.Schedule.Student.Something == studentSomething) .Include(class => class.Schedule.Student) 替换为<%= @articles.each do |article| %>

即可

说明: 在Ruby中,您不必指定返回值。每个方法的最后一个语句将自动返回。因此<% @articles.each do |article| %>将返回完整的数组。 erb标记@articles.each只打印它。