Forum: Ruby on Rails Escaping Arithmetic Symbols

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Joshua Schairbaum (Guest)
on 2006-02-28 23:08
(Received via mailing list)
Could someone please tell me how to escape the 'division' arithmetic
symbol in a model or controller?  I've searched around and cannot find a
solution.

I've got the following in my model:

  def avg_risk
    t = 0
    self.audits.each{|key| t = t + key.control_rating }
    t = t / self.audits.count #this line doesn't work... I've even tried
\/
    return t
  end

Any help would be appreciated.
685df76ebeb6c0d61ff5e0284830f691?d=identicon&s=25 Jim Cheetham (Guest)
on 2006-02-28 23:23
(Received via mailing list)
On Tue, Feb 28, 2006 at 10:07:50PM -0000, Joshua Schairbaum wrote:
> Could someone please tell me how to escape the 'division' arithmetic
> symbol in a model or controller?  I've searched around and cannot find a
> solution.

Well, what do you *want* to have happen?
And what *actually* happens?

Looks like you're trying to do arithmetic on those values - are you
sure they're numeric? Perhaps one of them is a string or something?

>
> I've got the following in my model:
>
>   def avg_risk
>     t = 0
>     self.audits.each{|key| t = t + key.control_rating }
>     t = t / self.audits.count #this line doesn't work... I've even tried \/
>     return t
>   end

-jim
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Joshua Schairbaum (Guest)
on 2006-03-01 02:01
(Received via mailing list)
On Tuesday, February 28, 2006, at 10:23 PM, Jim Cheetham wrote:
>
>Well, what do you *want* to have happen?
>And what *actually* happens?
>
>Looks like you're trying to do arithmetic on those values - are you
>sure they're numeric? Perhaps one of them is a string or something?
>

I'm sure that they're both numbers.  I cannot remember the exact error
number because I'm not at work, but the gist of it was the operation
could not be completed.

I think I'm going to try to install the arithmetic plugin for Rick
Olson...or wait for 1.1, all I'm trying to do is get an average value of
an attribute for a collection.
This topic is locked and can not be replied to.