Forum: Ruby on Rails Best Implementation Web-Configurable Custom Model Properties

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3252509ae024ded864bd341e893fab2d?d=identicon&s=25 Ethan Winn (Guest)
on 2007-01-16 18:36
(Received via mailing list)
Hello Railsians,

I'm hoping for some advice on the best way to implement a site that
will allow users to add custom properties to certain data models via a
web interface.  The basic use-case goes like this: admins have the
ability to create custom data fields for client records which users can
then edit and run reports on.  It seems the cleanest way to do this is
to implement some solution at the model level, and I wonder if an
appropriate solution has already been developed or if the ideas I'll
outline below are going in the right direction.

My solution to the problem of how to best implement user-configurable
data-models is to create three new "acts_as" methods to extend the
relevant models.  These methods would be something like
"acts_as_datafield_definition" and "has_datafields_defined_in" which
would be invoked like

class Client << AppModel
        has_datafields_defined_in CustomData

class CustomData << AppModel

In a very basic implementation the schema of the table associated with
the CustomData model would contain a name, a datatype (which in later
versions could be broken out into a separate customizable option of its
own) and perhaps a position ranking (for display in related add/edit
forms). Each CustomData entry would then be made available as a
property of the Client object. So if there were CustomData objects with
the names "favorite_vacation_spot" and "spouses_birthday", each Client
instance would have the properties client.favorite_vacation_spot and
client.spouses_birthday as if those were additional columns in the
clients table. The data would then be saved in a third table, say
"custom_data_datapoints" with hidden associations to the correct client
and custom_data records (so the schema would be something like
"client_id, custom_data_id, value").

Is there anything like this already out there or any other way of
getting this functionality using existing extensions? Is there a better
way of accomplishing this goal, say a plugin that might allow the
creation and modification of additional data tables for increased

If not, wish me luck, because this is going to be one of my first rails
plugins, and I think it might be a doozy. In advice on how to best
implement it?



Ps. Sorry if this is a dupe, I keep having posting wierdness with this
This topic is locked and can not be replied to.