Can't do a find_by_sql...returns '#'

Hello everyone, I'm trying to do a find_by_sql and every time my results are only returned as a pound sign '#'. What does this mean? Here is my query..

<%= Guestbook.find_by_sql "SELECT g.body from guestbooks g where g.id=(SELECT max(g.id) from guestbooks g)" %>

I'm just trying to retrieve the last post in the guestbook to display in a sidebar. No matter if I tried to calculate this in the Guestbook model or in the view it returned #. I couldn't even do a Guestbook.find(:all). That just returned as many # signs as there were db entries for the guestbooks table.

Any ideas?

Thanks, -Jon

Jonathan Kinney wrote:

Hello everyone, I'm trying to do a find_by_sql and every time my results are only returned as a pound sign '#'. What does this mean? Here is my query..

<%= Guestbook.find_by_sql "SELECT g.body from guestbooks g where g.id=(SELECT max(g.id) from guestbooks g)" %>

I'm just trying to retrieve the last post in the guestbook to display in a sidebar. No matter if I tried to calculate this in the Guestbook model or in the view it returned #. I couldn't even do a Guestbook.find(:all). That just returned as many # signs as there were db entries for the guestbooks table.

Any ideas?

Thanks, -Jon

Generally the '#' is generated when you try to print an object that doesn't know how to represent itself as a string.

Couple of pointers here.

try this...

<%= Guestbook.find(:first, :order=>'id DESC').body %>

This will print the body from the Guestbook entry with the highest id number. Assuming that 'body' is a string or text column, it should work fine.

_Kevin