views:

18

answers:

0

I have a Campaign model which I want the user to be able to check off and on a checkbox for each state, which I want to store in an array in one the fields, like ["CA", "NY", "OH", "FL"].

I'm not sure if serialized is the correct terminology here. I have some form fields generated like so:

<% State::NAMES.each do |state| %>
  <%= check_box("states_allowed", state[1], :checked => true) %>
  <label for="states_allowed_<%= state[1] %>"><%= state[0] %></label>
<% end %>

In which State::NAMES, is just an array of state names and abbreviations.

So this gives me the HTML of:

...
<input type="hidden" value="0" name="states_allowed[NE]"><input type="checkbox" value="1" name="states_allowed[NE]" id="states_allowed_NE">
<label for="states_allowed_NE">Nebraska</label>
...

But how can I save the check fields? The column content stays null and I don't receive an error.

Something I have tried is putting serialize :states_allowed in my Campaign model, but no luck.