我有這樣的模型。覆蓋屬性函數rails mongoid
class Money
include Mongoid::Document
#interval is how often the compensation is paid
field :salary, :type => Integer # must be saved in cents
field :commission, :type => Integer # must be saved in cents
field :total, :type => Integer # must be saved in cents
end
總計是工資和佣金的總和。薪水和佣金都以美分保存。 但我的問題是,當它被編輯時,我需要以美元數字顯示它。
例如,如果薪水分爲5000000,那麼當我按編輯我需要在工資文本框中看到50000。
一些其他的解決方案也受到了歡迎
感謝