title: How to properly setup checkboxes to save to database using Rails 4 and simple_form?
body: <p>I've created a form using the simple_form gem but can't get the values of the checkboxes to save. Radio buttons and select fields save perfectly.  I have found information on how to use the checkboxes with a model, but that's not what I'm trying to do. I'm passing the values as an array, but it looks like it needs a hash or something when I look at the html.  If I pass a hash I get the nasty red error page telling me my syntax is off. </p>
  
  <p>I'm pretty fairly new to rails, so maybe my entire approach to this form is wrong and I should be using a model? I did create a helper for the language file but had different errors and decided to concentrate on trying to save to the database.</p>
  
  <p>Any advice on how to setup the checkboxes correctly?</p>
  
  <p>languages html output</p>
  
  <pre><code>&lt;div class="control-group check_boxes optional program_languages"&gt;
  
  &lt;label class="check_boxes optional control-label"&gt;Languages&lt;/label&gt;
  
  &lt;div class="controls"&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_english" name="program[languages][]" type="checkbox" value="English" /&gt;English&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_portuguese" name="program[languages][]" type="checkbox" value="Portuguese" /&gt;Portuguese&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_italian" name="program[languages][]" type="checkbox" value="Italian" /&gt;Italian&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_russian" name="program[languages][]" type="checkbox" value="Russian" /&gt;Russian&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_korean" name="program[languages][]" type="checkbox" value="Korean" /&gt;Korean&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_german" name="program[languages][]" type="checkbox" value="German" /&gt;German&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_vietnamese" name="program[languages][]" type="checkbox" value="Vietnamese" /&gt;Vietnamese&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_tagalog" name="program[languages][]" type="checkbox" value="Tagalog" /&gt;Tagalog&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_french" name="program[languages][]" type="checkbox" value="French" /&gt;French&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_chinese" name="program[languages][]" type="checkbox" value="Chinese" /&gt;Chinese&lt;/label&gt;
  
  &lt;label class="checkbox"&gt;
  &lt;input class="check_boxes optional" id="program_languages_spanish" name="program[languages][]" type="checkbox" value="Spanish" /&gt;Spanish&lt;/label&gt;
  
  &lt;input name="program[languages][]" type="hidden" value="" /&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>programs_controller.rb</p>
  
  <pre><code>def index
     @programs = Program.all
  end
  
  def new
      @program= Program.new
  end
  
  def create
      @program = Program.new(program_params)
      if @program.save
          redirect_to @program
      else
          render action: "new"
      end
  end
  
  def edit
      @program = Program.find(params[:id])
  end
  
  def update
      @program = Program.find(params[:id])
  
      if @program.update_attributes(program_params)
          redirect_to programs_path
      else
          render action: "edit"
      end
  end
  
  def show
      @program = Program.find(params[:id])
    end
  
  def destroy
      @program = Program.find(params[:id])
      @program.destroy
      redirect_to programs_url
    end
  
    def program_params
      params.require(:program).permit(:programName, :contactName, :email, :phone, :address, :city, :state, :zip, :ageGroup, :offline, :online, :founded, :website, :linkedin, :twitter, :facebook, :programsOffered, :languages, :servicesOffered, :communityServed)
    end
  </code></pre>
  
  <p>new.html.erb</p>
  
  <pre><code>&lt;%= simple_form_for(@program, html: {class: 'form-horizontal' }) do |f| %&gt;
    &lt;%= f.input :programName %&gt;
    &lt;%= f.input :contactName %&gt;
    &lt;%= f.input :email, as: :email %&gt;
    &lt;%= f.input :phone, as: :tel %&gt;
    &lt;%= f.input :address %&gt;
    &lt;%= f.input :country, as: :country %&gt;
    &lt;%= f.input :state, collection: [ options_for_select(us_states)]  %&gt;
    &lt;%= f.input :city %&gt;
    &lt;%= f.input :zip %&gt;
    &lt;%= f.input :ageGroup, as: :check_boxes, collection: ['Any','Youth','Teen','Young Adult', 'Adult']  %&gt;
    &lt;%= f.input :offline, collection: ['Yes','No'],as: :radio_buttons %&gt;
    &lt;%= f.input :online, collection: ['Yes','No'], as: :radio_buttons %&gt;
    &lt;%= f.input :founded, collection: 1939..2014 %&gt;
    &lt;%= f.input :languages, collection: ['English','Portuguese','Italian','Russian','Korean','German','Vietnamese','Tagalog','French','Chinese','Spanish'], as: :check_boxes, include_blank: false %&gt;
   &lt;%= f.input :website, as: :url %&gt;
    &lt;%= f.input :linkedin, as: :url  %&gt;
    &lt;%= f.input :twitter, as: :url  %&gt;
    &lt;%= f.input :facebook, as: :url  %&gt;
    &lt;%= f.input :communityServed %&gt;
    &lt;%= f.input :servicesOffered %&gt;
    &lt;%= f.input :programsOffered %&gt;
    &lt;%= f.input :description %&gt;
    &lt;%= f.button :submit %&gt;
  </code></pre>
  
  
  
  <p>program.rb</p>
  
  <pre><code>  class Program &lt; ActiveRecord::Base
      has_many :positions
    end
  </code></pre>
  
  <p>schema.rb</p>
  
  <pre><code>create_table "programs", force: true do |t|
  t.datetime "created_at"
  t.datetime "updated_at"
  t.string   "programName"
  t.string   "contactName"
  t.string   "email"
  t.string   "phone"
  t.string   "address"
  t.string   "city"
  t.string   "state"
  t.string   "zip"
  t.string   "ageGroup"
  t.string   "offline"
  t.string   "online"
  t.string   "founded"
  t.string   "website"
  t.string   "linkedin"
  t.string   "twitter"
  t.string   "facebook"
  t.string   "communityServed"
  t.string   "servicesOffered"
  t.string   "programsOffered"
  t.text     "description"
  t.string   "languages"
  t.string   "country"
  </code></pre>
  
  <p>end</p>