# Help with Non-model classes

**URL:** <https://www.ruby-forum.com/t/help-with-non-model-classes/52176>\
**Category:** Rails\
**Created:** [January 11, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/help-with-non-model-classes/52176 "2006-01-11T18:35:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_van\_den\_Hoven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Adam\_van\_den\_Hoven](https://www.ruby-forum.com/u/Adam_van_den_Hoven)\
**Post date:** [January 11, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/help-with-non-model-classes/52176/1 "2006-01-11T18:35:44Z")

</div>

Hey guys,

I’ve been trying to teach myself Rails by building a relatively  
complex app for work. I’ve started it twice and now I’m thinking  
about restarting it a third time. I need some help with some of my  
code.

I’m creating an app to help us manage time. We have a number of  
developers on a number of teams who are assigned to any number of  
projects or change orders (small changes for specific clients). It  
can be a real challenge to communicate to everyone who is available  
to do this new project or change when.

This app tracks projects, the people who they are assigned to and how  
much effort they have put in, or plan to put in to those assignments  
each week.

Because this is effectively a weekly calendar, I created the idea of  
a week as a range of dates. In my original version, I had a weeks  
table in my database and the start and end dates of all my time  
sensitive objects were week\_id. In the second rendition, I still had  
my weeks table but everything date sensitive used a date, rather than  
an ID. This means that I don’t have to have a Week model, only a  
simple class.

My problem is that I’m not 100% sure where to put the class, how to  
include it in my app, and how to set up the testing (I have a lot of  
tests from the second round that would still be valuable).

Any thoughts?  
Adam

---

<div class="post-metadata">

**Author:** ![Adam\_van\_den\_Hoven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Adam\_van\_den\_Hoven](https://www.ruby-forum.com/u/Adam_van_den_Hoven)\
**Post date:** [January 11, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/help-with-non-model-classes/52176/2 "2006-01-11T19:04:33Z")

</div>

Why not create a class like Task?

## table tasks

id - integer  
date - date  
task - text

Then you can do a BETWEEN sql-query to find every task in a certain  
week.

Task.find(:all, :conditions =\> [‘date BETWEEN ? AND ?’, Time.now,  
1.week.from\_now])

I’m not sure if this works though.

---

<div class="post-metadata">

**Author:** ![Adam\_van\_den\_Hoven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Adam\_van\_den\_Hoven](https://www.ruby-forum.com/u/Adam_van_den_Hoven)\
**Post date:** [January 11, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/help-with-non-model-classes/52176/3 "2006-01-11T19:09:14Z")

</div>

On Jan 11, 2006, at 10:29 AM, Adam van den Hoven wrote:

> can be a real challenge to communicate to everyone who is available  
> still had my weeks table but everything date sensitive used a date,  
> rather than an ID. This means that I don’t have to have a Week  
> model, only a simple class.
> 
> My problem is that I’m not 100% sure where to put the class, how to  
> include it in my app, and how to set up the testing (I have a lot  
> of tests from the second round that would still be valuable).
> 
> Any thoughts?  
> Adam

Models don’t have to have a database connected to them, nor do they  
have to be ActiveRecord::Base-derived. Is there any reason you  
shouldn’t put it in the models directory? Doing so will still give  
you the benefit of auto-required classes as long as you follow the  
naming convention.

e.g.

# week.rb:

class Week

# … your code here …

end

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![Adam\_van\_den\_Hoven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Adam\_van\_den\_Hoven](https://www.ruby-forum.com/u/Adam_van_den_Hoven)\
**Post date:** [January 11, 2006, 9:23pm UTC](https://www.ruby-forum.com/t/help-with-non-model-classes/52176/4 "2006-01-11T21:23:39Z")

</div>

I didn’t realize that simply putting a file in /app/model makes it a  
model. I’ll do it that way. Will fixtures still work without a table?

Adam

---

<div class="post-metadata">

**Author:** ![Adam\_van\_den\_Hoven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Adam\_van\_den\_Hoven](https://www.ruby-forum.com/u/Adam_van_den_Hoven)\
**Post date:** [January 11, 2006, 11:40pm UTC](https://www.ruby-forum.com/t/help-with-non-model-classes/52176/5 "2006-01-11T23:40:56Z")

</div>

On Jan 11, 2006, at 1:21 PM, Adam Van Den H. wrote:

> I didn’t realize that simply putting a file in /app/model makes it  
> a model. I’ll do it that way. Will fixtures still work without a  
> table?

Well, sort of. You’re going to have to do a little more on your own,  
but it’s not that bad since most of what Rails helps with is reducing  
the work related to the database.

To get a fixture, just load it via yaml:

require ‘yaml’

my\_fixtures = YAML.load(IO.read(filename))

Where ‘filename’ is the name of the fixture file you want to load.

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)
