我在第三级的多级嵌套表单中遇到了问题。我的表格中涉及三个模型。
class School < ActiveRecord::Base
has_many :years
validates_presence_of :name
accepts_nested_attributes_for :years
end
class Year < ActiveRecord::Base
belongs_to :school
has_many :year_contacts
validates_presence_of :year_name
accepts_nested_attributes_for :year_contacts
end
class YearContact < ActiveRecord::Base
belongs_to :year
validates_presence_of :contact_name
end
这是我的表格:
<%= form_for @school, :validate => true do |f| %>
<h4>School</h4>
<%= f.label 'Name', :class => 'control-label' %>
<%= f.text_field :name, :class => 'span12', :placeholder => "School name" %>
<h4>Year of Graduating</h4>
<%= f.fields_for :years do |fo| %>
<%= fo.label 'Year' %>
<%= fo.text_field :year_name %>
<h4>Contact</h4>
<%= fo.fields_for :year_contacts do |foo| %>
<%= foo.label %>
<%= foo.text_field :contact_name %>
<% end %>
<% end %>
<%= f.submit %>
<% end %>
客户端验证就像学校属性和嵌套年份属性的魅力一样。但是当涉及到第三级嵌套时,它就不起作用了。year_contacts 属性没有任何客户端验证。
我不确定这是一个错误,client_side_validations 的已知限制还是我这边的错误。我发现的所有已知问题仅适用于嵌套在另一个模型下的两个模型,但没有像我这样的真正的多级结构。
我在github上开了一张票:https ://github.com/bcardarella/client_side_validations/issues/568
我使用 Rails 3.2.1 和 client_side_validations 3.2.5
表格效果很好。所有数据都按预期保存。