Giter VIP home page Giter VIP logo

acts_as_array's Introduction

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

acts_as_array's People

Stargazers

Angus H. avatar Rubén Dávila Santos avatar

Watchers

Rubén Dávila Santos avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.