2012-04-27 35 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