我已经向Product and Variants模板添加了一个字段MRP,但问题是,如果我第二次更新,如果MRP大于999意味着1000,那么它将除以千,并在字段中赋值为1.00。我怎么才能解决这个问题。
class AddMrpToVariant < ActiveRecord::Migration
def self.up
add_column :spree_variants, :mrp_price, :decimal, precision: 10, scale: 2
end
def self.down
remove_column :spree_variants, :mrp_price
end
end发布于 2019-04-09 20:34:45
通过将以下代码添加到模型中解决了此问题。
%w(mrp_price).each do |m|
define_method("#{m}=") do |argument|
self[m] = Spree::LocalizedNumber.parse(argument) if argument.present?
endhttps://stackoverflow.com/questions/54802933
复制相似问题