1
这里是一个初学者问题的位...在我的Rails应用程序中我有一个零件模型,我希望管理员能够对零件的价格应用折扣(如果他们想的话)。我的零件模型中折扣的价值是一个整数。我有我的部分模型内部的方法apply_discount红宝石/ Rails百分比到十进制
class Part < ActiveRecord::Base
has_many :order_items
belongs_to :category
default_scope { where(active: true)}
def apply_discount
new_price = self.discount.to_decimal * self.price
self.price - new_price
end
我得到的错误是所谓的“未定义的方法`to_decimal” 10:Fixnum对象” 每当你把折扣的百分比。任何想法如何我可以获得适当的折扣转换成浮动或小数?谢谢
非常感谢!像魅力一样工作 – Dan