I want to convert dollars to cents without using money gem and outside the model. This attribute belongs to model that is has a dashboard in Administrate gem.
When users input 10
it should be converted to cents as 10 * 100
and saved to DB.
I was trying to do it using administrate custom Field then setup getter and setter, but it doesn't work:
class ConvertToCentsField < Administrate::Field::Base
def to_s
data
end
def buyer_fee_fixed
@resource.buyer_fee_fixed
end
def buyer_fee_fixed=(value)
@resource.buyer_fee_fixed = (value.to_f * 100).to_i
end
end
Maybe I'm using getter and setter in the wrong place.