这是我的表格:
= form_for @talent do |f|
- if @talent.errors.any?
#error_explanation
%h2= pluralize(@talent.errors.count, "error")
"prohibited this user from being saved:"
%ul - @talent.errors.full_messages.each do |msg|
%li= msg
= f.label :First_Name
= f.text_field :first_name
= f.label :Last_Name
= f.text_field :last_name
= f.label :City
= f.text_field :city
= f.label :State
= f.text_field :state
= f.label :Zip_code
= f.text_field :zip_code
= f.label :Email
= f.text_field :email
= f.submit "Create"
这是我的错误消息:
Illegal nesting: nesting within plain text is illegal.
Extracted source (around line #7):
4: #error_explanation
5: %h2= pluralize(@talent.errors.count, "error")
6: "prohibited this user from being saved:"
7: %ul - @talent.errors.full_messages.each do |msg|
8: %li= msg
9:
10: = f.label :First_Name
我不知道我做错了什么。
最佳答案
首先,您的 %ul
行应该是单独的,其下有循环。另外,您的 %ul
行不应在上面的字符串下方缩进:
- if @talent.errors.any?
#error_explanation
%h2= pluralize(@talent.errors.count, "error")
"prohibited this user from being saved:"
%ul
- @talent.errors.full_messages.each do |msg|
%li= msg
但是您可能想要的是“禁止...”部分成为您的 h2
的一部分?如果是这样:
- if @talent.errors.any?
#error_explanation
%h2
= pluralize(@talent.errors.count, "error")
"prohibited this user from being saved:"
%ul
- @talent.errors.full_messages.each do |msg|
%li= msg
关于ruby-on-rails - 使用 haml 显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9344025/