我想让浏览器中突出显示的ActiveRecord验证错误从ASCIIcasts中吸取教训。 这是我的部分_errors_messages
<% if event.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(event.errors.count, "error") %> prohibited this record from being saved:</h2>
<ul>
<% event.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
这是我的html文件,它是从
生成的<%= form_for event, html: { class: "event-form" } do |f| %>
<%= render "shared/error_messages", :target => @event %>
<% unless current_user %>
<div class='row'>
<div class='col-md-4'>
<div class="form-group col-sm-12">
<%= label :email, "Enter your email:" %>
<%= text_field_tag :email, "",class: "form-control" %>
此错误浏览器显示
undefined local variable or method `event' for #<#<Class:0x007f117cc78c30>:0x007f117cdf5c48>
答案 0 :(得分:1)
event
应该是控制器中的实例变量,例如@event
。