Skip to content

Repository files navigation

Acts As Array

This plugin allow save an array of fields from a form into a single string column, avoiding the requirement of serialize an attribute.

The plugin in action

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

About

Plugin to implement array of fields in a form (like checkboxes) and save in a single string column

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages