2012-04-27 33 views
0

我正在学习本教程(http://ruby.railstutorial.org/chapters/sign-up#sec:signup_form)。然而,当清单代码在7.23(转换为HAML)在HAML上双重打印实例变量

=if @user.errors.any? 
%div{:id => "error_explanation"} 
    %div{:class=>"alert alert-error"} 
    il modulo contiene errori 
    %ul 
     = @user.errors.full_messages.each do |msg| 
     %li 
      = msg 

我结束了一个双重打印:预期的一个,接着是排序变量

Name can't be blank 
Password is too long (maximum is 15 characters) 
["Name can't be blank", "Password is too long (maximum is 15 characters)"] 
<h1>Registrazione nuovo utente</h1> <div id='error_explanation'> <div class='alert alert-error'> il modulo contiene errori <ul> <li> Name can't be blank </li> <li> Password is too long (maximum is 15 characters) </li> [&quot;Name can't be blank&quot;, &quot;Password is too long (maximum is 15 characters)&quot;]</ul> </div> </div> 

我的打印输出的对于rails编程来说真的很陌生,但我真的无法得到。

感谢,马塞罗

回答

2

if语句应该以-,不是=开始:

- if @user.errors.any? 

和你的循环应该太:

- @user.errors.full_messages.each do |msg| 

一般来说,如果你是试图从erb转换为haml,<% ... %>变成- ...<%= ... %>变成= ...

+0

谢谢。我应该多加注意! – piffy 2012-04-28 10:42:33