我正在对银行条目进行基本验证,并尝试在提交时显示错误。这是我的验证和HTML。
控制器:
class PagesController < ApplicationController
def index
@guestbook_entries = GuestbookEntry.all
@guestbook_entry = GuestbookEntry.new
render "welcome"
end
end
class GuestbookEntry < ActiveRecord::Base
validates :body, presence: :true
end
这是我的HTML:
<% form_for @guestbook_entry do |f| %>
<% if f.errors.any? %>
<% f.errors.full_messages.each do |m| %>
<li><%= m %></li>
<% end %>
<% end %>
<%= f.label :body, "Guestbook Entry:" %>
<%= f.text_area :body %>
<%= f.submit "Submit" %>
<% end %>
有什么想法吗?