Help with Non-model classes

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

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.

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/

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

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/