mercredi 13 janvier 2016

checkbox form ouput is not as expected

I'm having problems creating a checkbox form in rails 4. There are two issues, the first is that as well as next to each checkbox, at the end of the form all of the ids and names of the categories are printed out with additional ugly formatting in one big list. The second issue is that when I use

id: dom_id(category)

to assign unique ids to each field, all the options become pre-selected.

 <div class="field"> 
    <%= hidden_field_tag "user[category_ids][]", nil %>
    <%= UserCategory.all.each do |category| %>
      <%= check_box_tag 'user[category_ids][]', category.id, , id:  dom_id(category) %>
      <%= label_tag dom_id(category), category.name %><br>
    <% end %> 
  </div>

Ugly formatting at end of form:

[#<Category id: 1, name: "school">, #<Category id: 2, name: "college">, #<Category id: 3, name: "university">, #<Category id: 4, name: "post-graduation">, #<Category id: 5, name: "doctorate">, #<Category id: 6, name: "master">, #<Category id: 7, name: "bachelor">, #<Category id: 8, name: "grad">, #<Category id: 9, name: "middle-school">, #<Category id: 10, name: "junior-school">, #<Category id: 11, name: "senior-school">]

Help would be appreciated!

Thanks




Aucun commentaire:

Enregistrer un commentaire