对于此表单中的所有其他验证,我收到了很棒的内联错误消息,但无论我尝试什么,在为这些复选框点击提交后,我似乎都无法显示任何消息。验证工作正常,因为在我选中一个框之前不会提交表单,但我希望看到用户的一些反馈。
我的模型(精简):
class Resource < ActiveRecord::Base
attr_accessible :objective_ids
has_many :obsources, :dependent => :destroy
has_many :objectives, :through => :obsources
validates_presence_of :objective_ids, :message => "Must check at least one"
end
class Objective < ActiveRecord::Base
has_many :obsources, :dependent => :destroy
has_many :resources, :through => :obsources
end
我认为的形式(精简):
<%= simple_form_for @resource, remote: true, :validate => true, :html => { :id => "resource-form#{@resource.skill_id}" } do |f| %>
<%= f.hidden_field :skill_id, :value => @resource.skill_id %>
<%= f.association :objectives, :label => "Objectives Targeted (at least 1)", :collection => Skill.find("#{@resource.skill_id}").objectives, :as => :check_boxes, :label_method => lambda { |objective| "#{objective.content}" } %>
<%= f.submit %>
<% end %>
想法将不胜感激!