我在付费广告工作板上工作,并且正在使用#Payola-Payments(使用 Rails 应用程序实现Stripe 支付处理器)对应用程序上的每个工作职位收费。
这就是我喜欢做的事情:
选中复选框时,我希望应用程序扣除的价格从我的工作表中的默认设置价格更改为添加复选框的价值。
我喜欢做的事的图解说明:
选中此框后,假设我在作业表中的默认价格上增加了 20 美元。
架构.rb
注意:在我的工作表中设置了 200 美元的默认价格(即 20000 美分)。原因是 Payola-payments 文档中的要求。因此,任何时候任何人发布招聘广告,Stripe 都会从他/她的信用卡中扣除 200 美元。
ActiveRecord::Schema.define(version: 20160827065822) do
create_table "jobs", force: :cascade do |t|
t.string "title", limit: 255
t.string "category", limit: 255
t.string "location", limit: 255
t.text "description"
t.text "to_apply"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", limit: 255
t.integer "price", default: 20000
t.string "permalink", limit: 255
t.string "stripeEmail", limit: 255
t.string "payola_sale_guid", limit: 255
t.string "email", limit: 255
t.string "website", limit: 255
t.string "company_name", limit: 255
t.boolean "highlighted"
end
end
我为解决这个问题所做的工作:
我在我的模型(job.rb)中定义了一个调用price_modification
并调用before_save
它的方法,这样我的模型看起来像下面的代码但没有工作:
class Job < ActiveRecord::Base
include Payola::Sellable
before_save :price_modification
def price_modification
price
end
def price_modification=(new_price)
if :highlighted == t
self.price += (price + 2000)
else
self.price = new_price
end
end
end
提前致谢。
我正在使用Ruby 2.2.4
和Rails 4.2.5.1