Giter Club home page Giter Club logo

acts_as_configurable's Introduction

ActsAsConfigurable
==================

I often find myself adding boolean flags or switches to my models, which are hardly ever used.
Examples being:
  "some of our clients want to display the logo on the right, although most of them want it on the left"
  "some other client wants to hide error messages"

Now, we could add a database column for each of those,
but eventually we'll end up with massive columns, that it takes 10 minutes of downtime to migrate.
Or, we'll just end up with a messy DB model.

My solution is;
  "if it's sparse, stick some acts_as_configurable magic"

A separate table that stores all these random, sparsely populated, configurables.
Attaching them polymorphically.

Example
=======

class Organisation < ActiveRecord::Base
  acts_as_configurable :show_logo_on_side => {
    :default => "left",
    :options => ["left", "middle", "right"],
    :description => "Where should we put the logo?"},
end

It acts like a normal attribute.
with a default, that will be used if no other value has been set.

Want to stick it dynamically into a form,

<% Organisation.configurable_properties.each do |property, attribs| %>
  <li>
    <%= label_tag("organisation_#{property}", "#{property.to_s.titleize}:") %><%=select("organisation",property, attribs[:options]) %>
    <%= help_tooltip(attribs[:description]) %>
  </li>
<% end %>

Something like that :)

Copyright (c) 2008 [Matthew Rudy Jacobs], released under the MIT license

acts_as_configurable's People

Contributors

matthewrudy avatar

Watchers

 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.