我的模型中有许多标准的rails验证:
validates_presence_of :url_string
validates_uniqueness_of :url_string
validates_presence_of :stream_source
validates_presence_of :width
validates_presence_of :height
validates_presence_of :name
validates_uniqueness_of :name
validates_presence_of :customer_name
validates_presence_of :iframe_background_color
Run Code Online (Sandbox Code Playgroud)
如果我没有在我的表单中填写其中一个字段,那么我将按照预期返回到表单,但奇怪的是没有显示错误消息.我使用下面的代码来显示错误消息:
<% @camera.errors.full_messages.each do |error| %>
<p><%= error %></p>
<% end %
Run Code Online (Sandbox Code Playgroud)
我还试图打印出@ camera.errors对象,这就是显示的内容:
#<ActiveModel::Errors:0x12db19bc @base=#<Camera id: 1, stream_source: "test", width: 640, height: 360, active: true, name: "test", url_string: "CAYD19Vp", customer_name: "test", iframe_background_color: "#FFFFFF", online: true, created_at: "2011-08-30 15:54:16", updated_at: "2011-09-06 15:52:48", audio: true, iframe_text_color: "#FF00FF", iframe_link_color: "#FF0000", notes: "Some notes!", offline_image_file_name: "Cake.jpg", offline_image_content_type: "image/jpeg", offline_image_file_size: 196591, offline_image_updated_at: "2011-09-06 12:12:38", pull_stream_url: …Run Code Online (Sandbox Code Playgroud)