I'm trying to update a form that only updates the attribute set to false when not selected. They're currently defaulted to true (which is want I want) but if I click on one attribute it will update all of them to false. I only want to update only one in particular to be false, along with many other rows. I'm not sure how to do a check to say "if a selected attribute is chosen, update that one, else if the other attribute is selected update the other, and update all the collected/checked fields at once."
I've defined a collection in my routes:
resources :evidences do
put :score, on: :collection
end
This is my controller:
class EvidencesController < ApplicationController
def score
EvidenceScore.update_all({quality: false, alignment: false}, {id: params[:evidence_score_ids]} )
redirect_to observation_domain_indicator_evidences_path
end
end
This is my form:
<%= form_tag(score_observation_domain_indicator_evidences_path, :method => 'put') do %>>
<tr>
<th><h4> Evidence </h4></th>
<th><h4> Quality </h4></th>
<th><h4> Alignment</h4></th>
<th><h4> Quality(Your Score) </h4></th>
<th><h4> Alignment(Your Score) </h4></th>
</tr>
<% @indicator.evidence_scores.each do |evidence_score| %>
<tr>
<td><%= evidence_score.description %></td>
<td><%= check_box_tag("evidence_score_ids[]", evidence_score.id) %></td>
<td><%= check_box_tag("evidence_score_ids[]", evidence_score.id) %></td>
<td><%= evidence_score.quality ? "Yes" : "No" %></td>
<td><%= evidence_score.alignment ? "Yes" : "No" %></td>
</tr>
<% end %>
</table>
<%= submit_tag "Submit Scores" %>
<% end %>
As you click on the link below to a picture, on the second row, if I only select one of the checkboxes, both of them will update. I'm trying to have the ability where only one updates if I select one checkbox. By clicking on a checkbox and submitting it, it should render "No"
Here's a picture of what's happening.
https://www.dropbox.com/s/bhf1el4xdsrcox3/Screenshot%202014-03-02%2002.03.40.png