How to use own classes properly


#1

I am using rails just for few days
Now i am developing traffic reports for my local network
I had to build database queries manualy becouse ActiveRecord does not
support selection of multiple sum() fields in silgle query

Then i wrote special class QueryBuilder which makes query string from
the given conditions (group by, where, additinal fields to select etc).

I put QueryBuilder just after my controller file in the same file
And now in some cases i have troubles it’s public methods. Class itself
is visible, it is passible to create objects of this class, but methods
are not accessible after changes in routes.rb

Can anyone explain or point me to the related manual how to use own
classes which are not a model and not a controller.
I cannot extend my model becouse i should have few instances of my class


#2

hi

Then i wrote special class QueryBuilder which makes query string from
the given conditions (group by, where, additinal fields to select etc).
you should place this code within a model :slight_smile:

I put QueryBuilder just after my controller file in the same file
that’s bad, after you’ve moved your code just call the Model.method
from the controller

Enrico


“The only thing necessary for the triumph of evil
is for good men to do nothing”
Edmund Burke


#3

On Apr 20, 2006, at 7:36 AM, Enrico T. wrote:

Then i wrote special class QueryBuilder which makes query string from
the given conditions (group by, where, additinal fields to select
etc).

you should place this code within a model :slight_smile:

Model? That sounds an awful lot like controller code. Models aren’t
supposed to know about the web. :slight_smile:

How about a helper?


– Tom M.


#4

you should place this code within a model :slight_smile:

Model? That sounds an awful lot like controller code. Models aren’t
supposed to know about the web. :slight_smile:

How about a helper?
I assume Kostya is not talking about URL query string, but database
queries placed within a string. Otherwise the helper may be fine. :slight_smile:


“The only thing necessary for the triumph of evil
is for good men to do nothing”
Edmund Burke