2

I have the following form for the model below it:

    = 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"

Model:

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."}

I am able to successfully validate the other 3 fields in the form however I am having trouble validating the presence of the checkbox field :interest. I want to ensure that the user selects either one or both of the options. Thanks for your help

apardes
  • 4,272
  • 7
  • 40
  • 66

1 Answers1

2

You can try

acceptance: true

in you model.

validates :interest, acceptance: true
  • I thought this worked initially as it threw an error when both options were left empty but I can't seem to get it to validate when selecting either or both. – apardes Oct 30 '14 at 15:18