Topic: New Method to roundup an integer to the highest multiple of 10
I haven't written very many of my own methods in Rails but am in need of something that will round up a number to the next highest multiple of 10. I wrote the code which I'm sure is bloated but it works. My problem is, I'm having trouble calling it on an integer in my application.
At first I tried putting it in the application helper and have since moved it to my model and I'm wondering if I'm doing it correctly:
class Tester < ActiveRecord::Base
def self.roundup
if x.to_i >= 0 && x.to_i <= 10
z = 10
return z
elsif x.to_i > 10 && x.to_i <= 20
z = 20
return z
elsif x.to_i > 20 && x.to_i <= 30
z = 30
return z
else x.to_i > 30 && x.to_i <= 40
z = 40
return z
end
I am trying to call my the method like this in my controller:
@x = 8
@x.roundup
I am getting a controller error that says:
undefined method `roundup' for 1:Fixnum
any idears...?
thanks
jackster