Hello people, just wanted to know how to actually test returned value from sql statement like : @alreadyused = Promotioncodes.find_by_sql [ "select alreadyused from promotioncodes where id = ?", @codeid ] I would like to check whether @alreadyused has value 1 or 0 It doesn''t seem a simple if @alreadyused would word ... Regards Joel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 21 May 2008, at 14:40, joel wrote:> > Hello people, > > just wanted to know how to actually test returned value from sql > statement like : > > @alreadyused = Promotioncodes.find_by_sql [ "select alreadyused from > promotioncodes where id = ?", @codeid ] > > I would like to check whether @alreadyused has value 1 or 0 >find_by_sql returns an array of model objects: so foo = Promotioncodes.find_by_sql [ "select alreadyused from promotioncodes where id = ?", @codeid ] if foo.first.alreadyused? ... end Also there''s no need to break out find_by_sql for that foo = Promotioncodes.find @codeid if foo.alreadyused? ... end is more than enough (and in keeping with rails conversion that model would be Promotioncode (or even PromotionCode)) Fred> It doesn''t seem a simple if @alreadyused would word ... > > > Regards > > Joel > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok thank you very much, Also wanted to know while using update_attribute method, how to actually test that the attribute has effectively been updated ? ( need to test to trigger appropriate popup message ) Thanks again, Joel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
joel wrote:> just wanted to know how to actually test returned value from sql > statement like : > > @alreadyused = Promotioncodes.find_by_sql [ "select alreadyused from > promotioncodes where id = ?", @codeid ] > > I would like to check whether @alreadyused has value 1 or 0count_by_sql next, what''s wrong with PromotionCode.find_by_id(@codeid).alreadyused ? I would guess what''s wrong with it is your model names don''t follow Rails conventions, so you have not yet tuned your ActiveRecord calls to match them. -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---