我有一个带有模型验证的 Rails (3.1) 应用程序,该应用程序在触发时将模型和字段名称放在消息之前,例如:
个人资料图片 个人资料图片内容类型 个人资料图片只允许使用 jpeg、gif 和 png 文件
有没有办法避免这种情况,所以它写道:
model.rb 验证:个人资料图片只允许使用 jpeg、gif 和 png 文件
validates_attachment_content_type :profile_image,
:content_type => ['image/jpeg', 'image/png', 'image/gif'],
:message => "Only jpeg, gif and png files are allowed for profile pictures"
该错误在我的布局中作为此代码的一部分出现:
<% if object.errors.any? %>
<div class="alert alert-message error" data-alert="alert">
<a class="close" data-dismiss="alert">×</a>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>