如何在Ruby中抑制数组上的.each循环的输出?

Cre*_*ibe 1 ruby ruby-on-rails-4

我搜索过,似乎找不到有类似问题的人.我正在研究Michael Hartle的RoR教程,我发现了一个奇怪的问题.我一直在跟踪他对T的指示,除了Rails 4和Ruby 2.1与他正在使用的旧版本不同.如果用户尝试使用错误数据注册时返回错误,他会创建一个包含的erb文件,标题为_error_messages.html.erb这是文件的代码:

<% if @user.errors.any? %>
 <div class="error_explanation round padding_10">
   <h3 class="error_explanation">
     <%= pluralize(@user.errors.count, "error") %>
     prohibited this user from being saved:
   </h3>
   <p>There were problems with the following fields:</p>
   <ul>
   <%= @user.errors.full_messages.each do |msg| %>
     <li><%= msg %></li>
   <% end %>
   </ul>
 </div>
<% end %>
<br />
Run Code Online (Sandbox Code Playgroud)

现在,当他执行这段代码时,他会得到你所期望的.在User.new尝试无效后,@ user对象指定的无序错误列表.

但是,我得到的输出 - 实际的HTML - 是这样的:

<div class="error_explanation round padding_10">
   <h3 class="error_explanation">
     2 errors
     prohibited this user from being saved:
   </h3>
   <p>There were problems with the following fields:</p>
   <ul>

     <li>Password can&#39;t be blank</li>

     <li>Password is too short (minimum is 6 characters)</li>
[&quot;Password can&#39;t be blank&quot;, &quot;Password is too short (minimum is 6 characters)&quot;]   </ul>
 </div>
<br />
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我正在获得额外奖金的预期输出.还输出了完整的错误数组:[&quot;Password can&#39;t be blank&quot;, &quot;Password is too short (minimum is 6 characters)&quot;]

我已经看了一些抑制的建议 - 我已经尝试了我能想到的每一种排列,例如:

@user.errors.full_messages.each;nil do |msg|
#and
@user.errors.full_messages.each do;nil |msg|
#and
@user.errors.full_messages.each do |msg|;nil
#and
end;nil
Run Code Online (Sandbox Code Playgroud)

我发现语法不正确并不奇怪.我错过了什么?为什么全阵列转储?感谢任何伸出援助之手的人 - 这是相当令人沮丧的.

Aru*_*hit 6

=从线上删除<%= @user.errors.full_messages.each do |msg| %>.而已.