Hi, I have two questions: 1) How do you cast in RoR2? I have this: <% .... total = 0; (@person.quizzes).each { |a| puts total+=a } .... %> <%= total %> However, the compiler treats a as a string. I want it to be an number. Help? 2) How do I make this (http://github.com/activefx/ restful_authentication_tutorial/tree/master/) work in an application? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Re: #1--you want to call either .to_i or .to_f on your now-string variables. The former converts to integer, the latter to a floating point number. Also (and read this next bit w/the voice of the Simpson''s Comic Book Guy in your head) there is no compiler--ruby is an interpreted language, it has an interpreter. ;-) -Roy P.S. That calculation you show looks like it would be better put in a model. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Phil Sent: Monday, September 08, 2008 9:40 AM To: Ruby on Rails: Talk Subject: [Rails] Amateur Programmer Hi, I have two questions: 1) How do you cast in RoR2? I have this: <% .... total = 0; (@person.quizzes).each { |a| puts total+=a } .... %> <%= total %> However, the compiler treats a as a string. I want it to be an number. Help? 2) How do I make this (http://github.com/activefx/ restful_authentication_tutorial/tree/master/) work in an application? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
not sure what @person.quizzes refers to [so this might not apply here] but if it refers to an ActiveRecord association you could use the sum method in ActiveRecord like @person.quizzes.sum(:some_field). link with more details: http://api.rubyonrails.org/classes/ActiveRecord/Calculations/ClassMethods.html#M001261. welcome to rails. RSL On Mon, Sep 8, 2008 at 2:23 PM, Pardee, Roy <pardee.r-go57ItdSaco@public.gmane.org> wrote:> > Re: #1--you want to call either .to_i or .to_f on your now-string > variables. The former converts to integer, the latter to a floating point > number. > > Also (and read this next bit w/the voice of the Simpson''s Comic Book Guy in > your head) there is no compiler--ruby is an interpreted language, it has an > interpreter. ;-) > > -Roy > > P.S. That calculation you show looks like it would be better put in a > model. > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto: > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Phil > Sent: Monday, September 08, 2008 9:40 AM > To: Ruby on Rails: Talk > Subject: [Rails] Amateur Programmer > > > Hi, I have two questions: > > 1) How do you cast in RoR2? I have this: > <% .... > total = 0; > > (@person.quizzes).each { |a| puts total+=a } > > .... > %> > > <%= total %> > > However, the compiler treats a as a string. I want it to be an number. > Help? > > > > 2) How do I make this (http://github.com/activefx/ > restful_authentication_tutorial/tree/master/<http://github.com/activefx/restful_authentication_tutorial/tree/master/>) > work in an application? > > > > Thanks! > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---