From: Sean O'Dell Date: 2004-07-09T00:44:57+09:00 Subject: Re: best practice in ruby On Thursday 08 July 2004 03:48, Florian Weber wrote: > > the helper methods like editable_content are defined in my template > class. > > now comes the real question: the helper methods can be used in two > ways creating the objects which represent the editable_content (and > saving > it as a active record) and during the rendering, where the > editable_content > method will fill in the real content. > > would i just create something like: > > MyRenderingTemplateClass.new(my_template_object).render I would protect the data in a class designed primarily to save/load from an "active record" (whatever that is in your program). I would create a public initializer for the class so it can be created at any time, and I would give it a save method for saving. I would create a class factory method for the load function, and a public global method for rendering: class MyClass def initialize end def save end def MyClass::load(record_id) return new_myclass_instance end end def render_myclass(myclass_instance) end The render method might have a better home, but from what I could gather from your post, a simple public method should do fine. I'm not sure what sort of data you are dealing with, but if you can present it as a hash, with named keys and such, you might also provide a [] method and have the render method simply treat its parameter like a hash; try to make it generic, so you can test it disconnected from the class itself, or possibly re-use it elsewhere. Sean O'Dell