我在Active Admin中遇到了一个显示错误消息的问题。
我能够在表单字段中显示所有的错误消息。 但在下面的代码中,我需要至少添加一项技能和最多5项技能。 否则需要抛出一个错误消息。
我在模型中添加了一个验证:
validates :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