Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Plugin to implement array of fields in a form (like checkboxes) and save in a single string column
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
tasks
test
MIT-LICENSE
README
README.textile
Rakefile
init.rb
install.rb
uninstall.rb

README.textile

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

Something went wrong with that request. Please try again.