# How to use own classes properly

**URL:** <https://www.ruby-forum.com/t/how-to-use-own-classes-properly/58286>\
**Category:** Rails\
**Created:** [April 20, 2006, 8:59am UTC](https://www.ruby-forum.com/t/how-to-use-own-classes-properly/58286 "2006-04-20T08:59:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 20, 2006, 8:59am UTC](https://www.ruby-forum.com/t/how-to-use-own-classes-properly/58286/1 "2006-04-20T08:59:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 20, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/how-to-use-own-classes-properly/58286/2 "2006-04-20T16:37:39Z")

</div>

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 🙂

> 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

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 20, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/how-to-use-own-classes-properly/58286/3 "2006-04-20T18:34:39Z")

</div>

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 🙂

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

How about a helper?

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![Kostya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kostya](https://www.ruby-forum.com/u/Kostya)\
**Post date:** [April 28, 2006, 1:08pm UTC](https://www.ruby-forum.com/t/how-to-use-own-classes-properly/58286/4 "2006-04-28T13:08:04Z")

</div>

> > you should place this code within a model 🙂
> 
> Model? That sounds an awful lot like controller code. Models aren’t  
> supposed to know about the web. 🙂
> 
> 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. 🙂

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