【发布时间】:2012-11-15 09:59:06
【问题描述】:
我在活动管理员中显示错误消息时遇到问题。
我收到了与表单中的字段一起显示的所有错误消息。 但在下面的代码中,我需要添加至少一项技能和最多 5 项技能。 否则需要抛出错误消息。
我在模型中添加了一个验证:
验证 :skills, :length => { :minimum => 1, :maximum => 5, :message => " 应至少为 1 且小于 5"}
这完全验证,但没有显示错误消息。
谁能帮我显示错误信息。
以下是代码:
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "User", :multipart => true do
f.input :name
f.input :email, :as => :email
f.input :profile_name
f.input :date_of_birth
f.input :gender, :as => :select, :collection => Gender::GENDERS
end
f.inputs "Skills* ( minimum 1 & maximum 5 )" do
f.has_many :skills do |p|
if !p.object.nil?
# show the destroy checkbox only if it is an existing appointment
# else, there's already dynamic JS to add / remove new appointments
p.input :_destroy, :as => :boolean, :label => "Destroy?",
:hint => "Check this checkbox, if you want to delete this field."
end
p.input :description
p.input :title
end
end
end
end
【问题讨论】: