0
它在以前的rails版本中工作。我找不到解決方案。驗證複選框在Rails 3.2中不起作用
#Model
validate :branches_cannot_be_empty
def branches_cannot_be_empty
errors.add(:branches, "can't be empty") if branches.blank?
end
#View HAML
.field.checkbox
= f.label(:branch, "Assign to Branch")
-if @march.branch_ids.include? (branch.id)
=check_box_tag "branches[#{branch.id}]", 1, true
-else
=check_box_tag "branches[#{branch.id}]"
= branch.name