Forum: Ruby on Rails controller subroutines

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Craig W. (Guest)
on 2006-02-21 03:58
(Received via mailing list)
Trying to find this documented in the Agile book and don't see an
appropriate example so I am confused.

I have a method in my controller...

def performfind
  myfind = ["Select * from clients where ..."]
           even more...complicated find here

and within the controller, I want to use the 'myfind' string

How do I get the string back from the method (which I gather is supposed
to be in 'private' section)?

Brian H. (Guest)
on 2006-02-21 04:32
(Received via mailing list)
If I were you, I might think about making that a method on one of the
models, either as an instance method or a class method (depending on

in the client model

def self.find_special_clients
     Client.find_by_sql("select * from clients where blah = true and
something in ('this', 'that')

This keeps that sort of logic out of the controller.  Then in the
controller, you only need
   @results = Client.find_special_clients

Much cleaner, and also easier to write a unit test for that logic.

Don't forget, since it's a method, you could pass parameters into it as
Craig W. (Guest)
on 2006-02-21 05:03
(Received via mailing list)
Makes sense but I have a lot of different sort_by techniques that depend
upon a session variable so I can't simply put one find in my model.

What I am trying to accomplish is a very complicated 'conditions' string
and use it in various 'instance methods' (thanks for the language).

Thus I have the logic to condense a very complicated find into a string,
all I want is the methodology to get that string back to various methods
in my controller.

Craig W. (Guest)
on 2006-02-21 05:34
(Received via mailing list)
nevermind...I figured it out...

myfind = performfind
variable = result of method

doh - I am brain damaged...learned something new though


This topic is locked and can not be replied to.