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
end
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)?
Craig
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
your
needs).
in the client model
def self.find_special_clients
Client.find_by_sql("select * from clients where blah = true and
something in (‘this’, ‘that’)
end
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
well
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
nevermind…I figured it out…
myfind = performfind
variable = result of method
doh - I am brain damaged…learned something new though
Thanks
Craig