0

我正在关注本教程(http://ruby.railstutorial.org/chapters/sign-up#sec:signup_form)。然而,当清单 7.23中的代码(转换为 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 编程真的很陌生,但我真的不能。

谢谢, 马塞洛

4

1 回答 1

2

您的if陈述应以 a 开头-,而不是 a =

- if @user.errors.any?

你的循环也应该:

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

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

于 2012-04-27T23:52:14.460 回答