Skip to content

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

License

Notifications You must be signed in to change notification settings

rdavila/acts_as_array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages