Best place to put methods containing raw sql code

I’m porting a bunch of sql queries used to generate reports of various
kinds. I have a report controller that has no model and will contain
all
the actions that display report results. Where should I stick my
wrapper
methods for these queries. I don’t like having them stuck right in the
middle of my controller action code. Would the helper module for the
report
controller be a good place?

On Tue, May 24, 2011 at 3:58 PM, Kevin [email protected] wrote:

I’m porting a bunch of sql queries used to generate reports of various
kinds. I have a report controller that has no model and will contain all
the actions that display report results. Where should I stick my wrapper
methods for these queries. I don’t like having them stuck right in the
middle of my controller action code. Would the helper module for the report
controller be a good place?

Why not place them in the most appropriate model? Helpers really should
be
in terms of helping you format your views per se, not business logic.
You
definitely dont want it in the controller if it is at all involved (and
it
should be if you are resorting to raw sql.

On 24 May 2011 22:00, David K. [email protected] wrote:

Why not place them in the most appropriate model? Helpers really should be
in terms of helping you format your views per se, not business logic. You
definitely dont want it in the controller if it is at all involved (and it
should be if you are resorting to raw sql.

If there is no appropriate model then add one or more (not derived
from ActiveRecord) to hold the code.

Colin

On Tue, May 24, 2011 at 4:58 PM, Kevin [email protected] wrote:

I’m porting a bunch of sql queries used to generate reports of various
kinds. I have a report controller that has no model and will contain all
the actions that display report results. Where should I stick my wrapper
methods for these queries. I don’t like having them stuck right in the
middle of my controller action code. Would the helper module for the report
controller be a good place?

A model does not necessarily have to have an associated table. It is
still
the place you want to put business logic. So, go ahead and create a
model
for this stuff, just don’t have it inherit from ActiveRecord::Base. It
won’t inherit from anything.

Jamey

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs