lundi 18 janvier 2016

Validating checkboxes in Ruby on rails

I have a form to submit recipes, but I need to check if the user selected some ingredents and implements

<div class="field">
    <label> ingredientes </label>
    <br>
    <% @ingredients.each do |ingredient| %>
    <div class="field">
      <dd><%= check_box_tag "Ingredients[]", ingredient.id %> <%= ingredient.nombre %></dd>
    </div>
    <% end %>
  </div>

  <div class="field">
    <label> implementos </label>
    <br>
    <% @implements.each do |implement| %>
    <div class="field">
      <dd><%= check_box_tag "Implements[]", implement.id%> <%= implement.nombre %></dd>
    </div>
    <% end %>
  </div>

Anyway, I want to limit the number of ingredents to 10 and implements to 5, but i think I can do that in the controller but my problem is I dont know how to validate that the user selected at least one checkbox, if I use

:required => true

it make all checkboxes checked by default and I dont want that




Aucun commentaire:

Enregistrer un commentaire