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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---