Reputation: 39
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
Upvotes: 1
Views: 925
Reputation: 3139
The top comment in the API points it out correctly, your 'false'
has to be nil
.
<%= f.check_box(:level, { :multiple => true, :id => 'level1', :class => 'input_values levels' }, 'All', nil) %>
Upvotes: 1