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 On 2/20/06, Craig White <craigwhite@azapple.com> wrote:> > 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060221/7e823809/attachment.html
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 On Mon, 2006-02-20 at 20:31 -0600, Brian Hogan wrote:> 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 > > > > > > > On 2/20/06, Craig White <craigwhite@azapple.com> wrote: > 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
nevermind...I figured it out... myfind = performfind variable = result of method doh - I am brain damaged...learned something new though Thanks Craig On Mon, 2006-02-20 at 19:59 -0700, Craig White wrote:> 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 > > On Mon, 2006-02-20 at 20:31 -0600, Brian Hogan wrote: > > 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 > > > > > > > > > > > > > > On 2/20/06, Craig White <craigwhite@azapple.com> wrote: > > 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 > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails