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?

  1. How do I make this (activefx (Matt Solt) · GitHub
    restful_authentication_tutorial/tree/master/) work in an application?


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. :wink:


P.S. That calculation you show looks like it would be better put in a

not sure what @person.quizzes refers to [so this might not apply here]
if it refers to an ActiveRecord association you could use the sum method
ActiveRecord like @person.quizzes.sum(:some_field). link with more
welcome to rails.