jeudi 8 février 2018

How to save different values for the checkbox field labels, in ruby on rails?

I have a collection checkboxes in my form, like below.

  <% ["cricket" ,"tennis", "not there in list"].each do |c| %>
    <div class="col-md-4" >
      <p><%= f.check_box :game, {:multiple => true, checked: @training.game&.include?(c), class: "reason-for-the-test"}, c, "" %>&nbsp;<%= c.capitalize.tr("_"," ") %></p>
    </div>
  <% end %>

Currently the label of the checkbox, and its value that is getting saved in the db, both are same. i want to save different values to the db for the labels. i tries like below. but its not working. can anyone help me with this.

  <% [["cricket","cri"] ,["tennis","ten"], ["not there in list","na"]].each do |c| %>
    <div class="col-md-4" >
      <p><%= f.check_box :game, {:multiple => true, checked: @training.game&.include?(c), class: "reason-for-the-test"}, c, "" %>&nbsp;<%= c.capitalize.tr("_"," ") %></p>
    </div>
  <% end %>




Aucun commentaire:

Enregistrer un commentaire