我正在面临一个问题,显示活动管理员中的错误消息.
我收到窗体中显示的所有错误消息.
但是在下面的代码中,我需要至少一个技能,最多可以添加5个技能.
否则需要抛出一个错误信息.
我在模型中添加了一个验证:
验证:技能,: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
解决方法
activeadmin 0.5.1在github上可用.
它包含更改日志中的下一行
它包含更改日志中的下一行
“Add support for semantic errors #905 by @robdiciuccio”
这里是拉这个功能的请求
https://github.com/gregbell/active_admin/pull/905
例
form do |f| f.semantic_errors *f.object.errors.keys f.inputs f.inputs "Locations" do f.has_many :locations do |loc| loc.input :address loc.input :_destroy,:label => "Delete" end end f.buttons end
使用它添加到Gemfile
gem 'activeadmin',:git => "git://github.com/gregbell/active_admin.git",:tag => "v0.5.1"