我遵循本教程(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> ["Name can't be blank", "Password is too long (maximum is 15 characters)"]</ul> </div> </div>
我对rails编程非常陌生,但我真的无法获得。
谢谢,Marcello
答案 0 :(得分:2)
您的if
声明应以-
开头,而不是=
:
- if @user.errors.any?
你的循环也应该如此:
- @user.errors.full_messages.each do |msg|
通常,如果您尝试将erb转换为haml,则<% ... %>
变为- ...
而<%= ... %>
变为= ...