Hi all, If someone could give me a clue as to how I would build the result of a query into a variable and echo it, it would be very appreciated. The below is not working, as it echos only a ''#'' to the browser. def endofmonth #using ? for future hardcoding it for debugging counter = Servers.find_by_sql [''SELECT count(*) FROM servers WHERE server LIKE ?'', "%GAR%" ] render_text counter end Thanks in advance.
Michael Koziarski
2005-Apr-26 01:30 UTC
Re: newb help please with building query into variable
On 4/26/05, Ron Sweeney <ron.sweeney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > If someone could give me a clue as to how I would build the result of > a query into a variable and echo it, it would be very appreciated. > > The below is not working, as it echos only a ''#'' to the browser. > > def endofmonth > > #using ? for future hardcoding it for debugging > > counter = Servers.find_by_sql [''SELECT count(*) FROM servers WHERE > server LIKE ?'', "%GAR%" ] > > render_text counter >You want count_by_sql http://rails.rubyonrails.com/classes/ActiveRecord/Base.html#M000661 Also, view source in the response, it isn''t just a # there''s stuff in the <> too.> > Thanks in advance. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz