Forum: Ruby on Rails how to use own classes properly

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.
Kostya (Guest)
on 2006-04-20 10:59
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
Enrico T. (Guest)
on 2006-04-20 18:37
(Received via mailing list)
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
Tom M. (Guest)
on 2006-04-20 20:34
(Received via mailing list)
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.
Enrico T. (Guest)
on 2006-04-28 15:08
(Received via mailing list)
> > 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
This topic is locked and can not be replied to.