On 22 Sep 2008, at 14:31, Brad Symons wrote:
> > im trying to use find_by_sql, i think its a very useful function, > but im > having trouble using it. Actually it is very rarely of use > > > in my outcomes table i have: > id status > 1 pass > 2 fail > 3 pass > 4 pass > > in my controller im trying to set it like this: > @status = Outcome.find_by_sql "select status from outcomes where id > = 1" > This would be better off as Outcome.find 1 > and in my outcome view > > <body> > <%= @status %> > <%= "[EMAIL PROTECTED]" %> > </body> > > when viewing the outcome.rhtml > > it just appears as '#' > > ultimately i am not convinced the find_by_sql is working at all...? it is working. It's just not what you think it is. @status is an array of Outcome objects. when you call to_s on an array (which is effectively what you're doing with the <%= ), arrays just call to_s on their contents and join them. to_s on activerecord objects gives you something like #<Customer:0x2146688> which is invalid html (browsers frequently ignore everything between the <>). If you follow my suggestion and do @outcome = Outcome.find 1 then you could stick <%= h @outcome.status %> in your view (the h function escapes the text making it safe for html Fred --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

