Piy*_*ary 17 ruby-on-rails activeadmin
我正面临一个问题,显示活动管理员中的错误消息.
我收到与表单中的字段一起显示的所有错误消息.但是在下面的代码中,我需要添加至少一项技能和最多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
Run Code Online (Sandbox Code Playgroud)
Fiv*_*ell 36
activeadmin 0.5.1在github上可用.它包含changelog中的下一行
"添加对@robdiciuccio的语义错误#905的支持"
这是带有此功能的pull请求 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, :as => :boolean, :label => "Delete"
end
end
f.buttons
end
Run Code Online (Sandbox Code Playgroud)
使用它添加到Gemfile
gem 'activeadmin', :git => "git://github.com/gregbell/active_admin.git", :tag => "v0.5.1"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11138 次 |
| 最近记录: |