Ethan Winn
2007-Jan-16 17:16 UTC
Best Implementation Web-Configurable Custom Model Properties?
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 ... end class CustomData << AppModel ... acts_as_datafield_definition ... end 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 efficiency? 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? Thanks, Ethan Ps. Sorry if this is a dupe, I keep having posting wierdness with this group! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---