【发布时间】:2014-10-27 03:30:45
【问题描述】:
下面的模型我有以下表格:
= simple_form_for @mem, :url => signup_path, :html => {:id => 'signup_form'}, :method => :post do |f|
= f.input :interest, label: "I would like to learn more about:", collection: [ ['Interest 1', 'Interest 1' ], ['Interest 2', 'Interest 2']], :as => :check_boxes
%br
= f.input :full_name, :as => :string, required: true
= f.input :email, :as => :string, required: true
= f.input :telephone, :as => :string, required: true
= f.submit "Submit"
型号:
class User
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :full_name, :email, :telephone, :interest
validates :interest, presence: { :message => "Please select your interest."}
我能够成功验证表单中的其他 3 个字段,但是我无法验证复选框字段 :interest 的存在。我想确保用户选择其中一个或两个选项。感谢您的帮助
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 haml