Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Avoid cluttering your Rails models, ActsAsConfigurable abstracts all your configuration away with a polymorphic config store

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 generators ActsAsConfigurable will hide away your string config in a polymorphic… October 06, 2008
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 tasks
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
README
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
Something went wrong with that request. Please try again.