Hello, I have a query that returns a number and I want to use that number after that. Could you please let me know how to access the data. I fire the query like: numscens = Progression.find_by_sql("select numscenarios from progressions where id = #{params[:progressionid]}") How can I access and use the numscenarios returned by the query that is part of my numscens variable now. If I do a numscens.to_xml I get: <?xml version="1.0" encoding="UTF-8"?> <resultdetails> <resultdetail> <numscenarios type="integer">2</numscenarios> </resultdetail> </resultdetails> Still I cannot figure out how to access that number in numscenarios tag. I want to do if (numscens == 1) do this else that... Apologies for the novice question. Many Thanks, Aman -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Zach Inglis // LT3media
2007-May-23 05:58 UTC
Re: Retrieving text from a query fired in Rails
Why don''t you just use: numscens = Progression.find(:first, :condition => :id => params [:progressionid]), or even simpler: numscens = Progression.find(params[:progressionid]) I believe, inserting the params directly like that can make you open for SQL injection attacks. And then, to use it from there, just use: numscens. If you want to make it available to your view, use: @numscens = .... then use <%= @numscens %> anywhere in your view On May 23, 2007, at 12:46 AM, Aman Thind wrote:> > Hello, > > I have a query that returns a number and I want to use that number > after > that. > > Could you please let me know how to access the data. > > I fire the query like: > > numscens = Progression.find_by_sql("select numscenarios from > progressions where id = #{params[:progressionid]}") > > How can I access and use the numscenarios returned by the query > that is > part of my numscens variable now. > > If I do a numscens.to_xml I get: > > <?xml version="1.0" encoding="UTF-8"?> > <resultdetails> > <resultdetail> > <numscenarios type="integer">2</numscenarios> > </resultdetail> > </resultdetails> > > Still I cannot figure out how to access that number in numscenarios > tag. > > I want to do if (numscens == 1) do this else that... > > Apologies for the novice question. > > Many Thanks, > Aman > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---