samedi 24 décembre 2016

Rails collection_check_boxes with Main type as well it's subtypes

Iam Working on an Event Management System, where i have HABTM between events and employees, I have created a checkbox with employees name like this,

<%= f.collection_check_boxes :employee_ids, Employee.all, :id,    
     :emp_name do |e| %>
       <div class="collection-check-box-subtypes">
       <%= e.check_box %>
           <%= e.label %>
       </div>
<%end%>  

but there are so many employees, therefore i want my employees to be selected by their department as well, so that it becomes more easy to select employees by departments rather than indiviually. And i also want to keep select all checkbox which is working right now perfectly. Therefore in short i want to create a checkbox like selectall/deselect all, than below the department name checkbox and under department the employees of that departments. Iam currently displaying the checkbox in front of the name of the departments, but it is not working as i want, below is the code: Select/Deselect All

  <% @employees.each do |department, employee|%>
  <input type="checkbox" name="" value="selectDepartment" id="selectDepartment">
    <label for="selectDepartment">
      <%= department.name%>
    </label><br>
      <div class="field">
        <div class="sub_check_box">
          <%= f.collection_check_boxes :employee_ids, employee, :id, :emp_name do |e| %>
              <div class="collection-check-box-subtypes">
                <%= e.check_box %>
                <%= e.label %>
              </div>
          <%end%>  
        </div>
      </div>
  <%end%>

Please if anyone can help me.

Aucun commentaire:

Enregistrer un commentaire