Are there any issues with creating model classes whose instances will never be stored persistently? Or is this the wrong way to be thinking about the problem? I need some classes of objects to help work with my model data. These classes don''t appear to naturally fit as helpers or components - they are just volatile extensions of the model that are only useful to help organize and transform the model data (example: a Week class to help organize data that is stored on a daily basis). So where is a good place to put these classes in a Rails app? Should they go in the model directory even if they aren''t based on ActiveRecord? Are there any tricks to working with them, like will Rails require their code automatically, or will I need to put those requires statements in myself? thanks joshua
just drop a regualr class into models and it will get picked up... if you do a easonable sized app there be a lot of models/objects that arent persistable... Mikkel Joshua Susser wrote:> Are there any issues with creating model classes whose instances will > never be stored persistently? Or is this the wrong way to be > thinking about the problem? I need some classes of objects to help > work with my model data. These classes don''t appear to naturally fit > as helpers or components - they are just volatile extensions of the > model that are only useful to help organize and transform the model > data (example: a Week class to help organize data that is stored on a > daily basis). So where is a good place to put these classes in a > Rails app? Should they go in the model directory even if they aren''t > based on ActiveRecord? Are there any tricks to working with them, > like will Rails require their code automatically, or will I need to > put those requires statements in myself? > > thanks > joshua-- Posted via http://www.ruby-forum.com/.
Hi, On 12/14/05, Joshua Susser <joshua-ZE1BUrLza8VWk0Htik3J/w@public.gmane.org> wrote:> Are there any issues with creating model classes whose instances will > never be stored persistently? Or is this the wrong way to be > thinking about the problem? I need some classes of objects to help > work with my model data.It depends on what you are doing. If you want to use the classes as backing for forms then you can use a technique like that outlined in either [1] or [2]. Putting them in model makes it easy for rails to find them (else you will need a ''require'').> Are there any tricks to working with them, > like will Rails require their code automatically, or will I need to > put those requires statements in myself?If you want your model to be reloaded in development mode you will need to use a technique described at the end of [1] [1] http://www.realityforge.org/articles/2005/12/02/validations-for-non-activerecord-model-objects [2] http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model -- Cheers, Peter Donald Blog: http://www.RealityForge.org