mardi 5 avril 2016

Rails, f.check_box returns both true and false when checked

I my app I have some checkboxes for an array called "level", each one looks like this(just with different values):

<%= f.check_box(:level, { :multiple => true, :id => 'level1', :class => 'input_values levels' }, 'All', 'false') %>

My problem is that when I check a box, I get both the value and 'false'. If I set the 'false' to nil, I get nothing when I uncheck the box.

If I for example, have the choice between - all - easy (checked) - intermediate (checked) - hard

I need the "level" array to print out something like this:

[ 'false', 'easy', 'intermediate', 'false']

Right now it's printing out something like this:

[ 'false', 'false', 'easy', 'false', 'intermediate', 'false']

My ActiveRecord::Base

serialize :level, Array

My controller

def gamesession_params
      params.require(:gamesession).permit(:players, :flares, :aliens, :gamesetup, expansion:[], level:[])    
end




Aucun commentaire:

Enregistrer un commentaire