title: Changing a select input to a checkbox acting as an on/off toggle switch in Rails
body: <p>I have a set of 7 dropdown inputs allowing admins to say whether they are open or closed for business on a given day. I'd like that changed to 7 open/closed switches (presumably styled checkboxes?) but can't figure out how to do this!</p>
  
  <p>Here are the relevant bits of code I currently have (prior to any change):</p>
  
  <p><strong>app/view/backend/inventory_pool/edit.html.haml</strong></p>
  
  <pre><code>- content_for :title, @inventory_pool
    = form_for [:backend, @inventory_pool], html: {name: "form"} do |f|
  
      .content
        - if is_admin?
          %a.button{:href =&gt; root_path}= _("Cancel")
        %button.button{:type =&gt; :submit}= _("Save %s") % _("Inventory Pool")
  
        %section
          %h2= _("Basic Information")
          .inner
            .field.text
              .key
                %h3= "#{_("Print Contracts")}"
                %p.description
              .value
                .input
                  %input{type: "checkbox", name: "inventory_pool[print_contracts]", checked: @inventory_pool.print_contracts}
  
  
        %section#workdays
          %h2= _("Workdays")
          .inner
            - [1,2,3,4,5,6,0].each do |i|
              .field.text
                .key
                  %h3= "#{I18n.t('date.day_names')[i]}"
                .value
                  .input
                    %select{:name =&gt; "store[workday_attributes][workdays][]"}
                      %option{:label =&gt; _("Open"), :value =&gt; Workday::WORKDAYS[i]}= _("Open")
                      %option{:label =&gt; _("Closed"), :value =&gt; "", :selected =&gt; @store.workday.closed_days.include?(i) ? true : nil}= _("Closed")
  </code></pre>
  
  <p><strong>app/models/workday.rb</strong></p>
  
  <pre><code>class Workday &lt; ActiveRecord::Base
  
    belongs_to :inventory_pool
  
    WORKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
  
    def is_open_on?(date)
  
      return false if date.nil?
  
      case date.wday
      when 1 return monday
      when 2 return tuesday
      when 3 return wednesday
      when 4 return thursday
      when 5 return friday
      when 6 return saturday
      when 0 return sunday
      else
        return false #Should not be reached
      end
    end
  
    def closed_days
      days = []
      days &lt;&lt; 0 unless sunday
      days &lt;&lt; 1 unless monday
      days &lt;&lt; 2 unless tuesday
      days &lt;&lt; 3 unless wednesday
      days &lt;&lt; 4 unless thursday
      days &lt;&lt; 5 unless friday
      days &lt;&lt; 6 unless saturday
      days
    end
  
    def workdays=(wdays)
      WORKDAYS.each {|workday| write_attribute(workday, wdays.include?(workday) ? true : false)}
    end
  end
  </code></pre>
  
  <p>And in <strong>app/controllers/backend/inventory_pools_controller</strong> I have this (abridged):</p>
  
  <pre><code>  def update
      @inventory_pool ||= InventoryPool.find(params[:id])
      process_params params[:inventory_pool]
    end
  
    def process_params ip
      ip[:print_contracts] ||= "false" # unchecked checkboxes are *not* being sent
      ip[:workday_attributes][:workdays].delete "" if ip[:workday_attributes]
    end
  </code></pre>