samedi 5 août 2017

Update Attribute for Unchecked Boxes

I've got a form with checkboxes. The user (a classroom teacher) clicks the objectives he wants to be considered as pretests.

The controller then sets the :pretest value to "1" for each record that is checked.

The controller also needs to make sure that any unchecked boxes set the :pretest value to "0" for each record that is not checked.

So far, I'm doing this by first setting EVERYTHING to zero, and then updating the checked boxes. But I suspect that there is a more rails-y way of doing this.

   def update_pretests
        @seminar = Seminar.find(params[:seminar_id])
        @seminar.objective_seminars.update_all(:pretest => 0)
        ObjectiveSeminar.where(:id => params[:pretest_on]).update_all(:pretest => 1)
    end

Thank you in advance for any insight!




Aucun commentaire:

Enregistrer un commentaire