我正在按照教程在一个新项目中使用money-rails。
这是我的迁移文件:
class AddFieldsToPlan < ActiveRecord::Migration[5.1]
def change
add_column :plans, :payment_gateway_plan_identifier, :string
add_column :plans, :price, :integer
add_column :plans, :interval, :integer
add_column :plans, :interval_count,:integer
add_column :plans, :status,:integer
remove_column :plans, :amount
remove_column :plans, :payment_frequency
end
end
我的模型:
class Plan < ApplicationRecord
enum status: {inactive: 0, active: 1}
enum interval: {day: 0, week: 1, month: 2, year: 3}
monetize :price_cents
def end_date_from(date = nil)
date ||= Date.current.to_date
interval_count.send(interval).from_now(date)
end
end
我阅读了money-rails的所有API规范,但我猜不太理解。
如果我运行 rails 控制台并执行 Plan.last.price 它会显示此错误:
.3.4 :001 > Plan.last.price
Plan Load (2.6ms) SELECT "plans".* FROM "plans" ORDER BY "plans"."id" DESC LIMIT $1 [["LIMIT", 1]]
NoMethodError: undefined method `price_cents' for #<Plan:0x007f8ca807f8f0>
Did you mean? price_cents=
from (irb):1
我在这里做错了什么?如何为此价格属性设置值?
谢谢