Updating the checkboxes with data from the db

I’m making a musicians site where the users are able to check some
checkboxes with their music-style if they want to edit their music-style
i would like the previous checked checkboxes to be checked.

here’s some code

<%= label %>: <% @i = 0 %> <% @status = false%> <% collection.each do |db_field| %> <% db_collection.split(", ").each do |collection_field| %> <% if db_field == collection_field %> <% @status = true %> <% else %> <% @status = false%> <% end %> <% end %> <% if @i == 1 %> <% @i = -1 %> <% end %> <% @i = @i +1 %> <% end %>
<%= check_box_tag array, db_field, @status %> <%= db_field %>

collection could be:

VALID_STYLES = [“Blues”, “Country”, “Elektronisk”, “Folkemusik”,
“Hip-Hop”,
“Jazz”, “Klassisk”, “Metal”, “Pop”, “R&B og Soul”,
“Rock”,
“Verdensmusik”]

and the db_collection could be:

Blues, Elektronisk, R&B og Soul

I don’t know why, but with the code i have now R&B og Soul would get
updated in the view so that the checkbox would be checked, it’s always
the last option that gets checked.