This plugin allow save an array of fields from a form into a single string column, avoiding the requirement of serialize an attribute.
In the model:
class Preference < ActiveRecord::Base
acts_as_array :colors # :separator => ',' (default)
COLORS = [
['Red', 1],
['Blue', 2],
['Brown', 3]
]
end
The colors attribute is a single string column.
In the form:
- form_for @preference do |f|
%p
= hidden_field_tag 'preference[colors][]', ''
- Preference::COLORS.each do |c|
= check_box_tag "preference[colors][]", c[1], @preference.colors.include?(c[1].to_s)
= c[0]
Copyright © 2009 Rubén Dávila Santos, released under the MIT license