# Amateur Programmer

**URL:** <https://www.ruby-forum.com/t/amateur-programmer/148059>\
**Category:** Rails\
**Created:** [September 8, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/amateur-programmer/148059 "2008-09-08T20:20:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 8, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/amateur-programmer/148059/1 "2008-09-08T20:20:23Z")

</div>

Hi, I have two questions:

1. How do you cast in RoR2? I have this:  
\<% …  
total = 0;

\<%= 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](http://github.com/activefx/)  
restful\_authentication\_tutorial/tree/master/) work in an application?

Thanks!

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 8, 2008, 8:33pm UTC](https://www.ruby-forum.com/t/amateur-programmer/148059/2 "2008-09-08T20:33:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 8, 2008, 10:21pm UTC](https://www.ruby-forum.com/t/amateur-programmer/148059/3 "2008-09-08T22:21:08Z")

</div>

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](http://api.rubyonrails.org/classes/ActiveRecord/Calculations/ClassMethods.html#M001261).  
welcome to rails.

RSL
