我有两个导轨型号,用法和价格。到目前为止,它们看起来像这样:
class Usage < ActiveRecord::Base
has_one :price
def spend
usage.amount * price.amount
end
end
和
class Price < ActiveRecord::Base
belongs_to :usage
end
我试图通过在控制台中执行此操作来调用“spend”:
Usage.create(amount:100)
Price.create(amount:0.1)
usage=Usage.find(1)
puts usage.price
我哪里错了??