Forum: Ruby on Rails volatile model classes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
17acfbd3a05cfb59e0543235cc0a813b?d=identicon&s=25 Joshua Susser (Guest)
on 2005-12-13 17:41
(Received via mailing list)
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
C7669e8b5676f61fdf202230cbcf72d8?d=identicon&s=25 mikkel <mikkel@helenius.dk> (Guest)
on 2005-12-13 18:09
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
67b6389be42524fbd776e44fd35c3d7e?d=identicon&s=25 Peter Donald (Guest)
on 2005-12-14 04:25
(Received via mailing list)
Hi,

On 12/14/05, Joshua Susser <joshua@tiralorn.com> 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/va...
[2]
http://rails.techno-weenie.net/tip/2005/11/19/vali...

--
Cheers,

Peter Donald

Blog: http://www.RealityForge.org
This topic is locked and can not be replied to.