【发布时间】:2015-07-27 23:19:54
【问题描述】:
在我的应用中,当买家从卖家那里购买商品时,买家的积分会归卖家所有。 这是控制器中的逻辑(gig = 是产品)
def downloadpage
ActiveRecord::Base.transaction do
if current_user.points >= @gig.pointsneeded
current_user.points -= @gig.pointsneeded
@gig.user.points += @gig.pointsneeded
current_user.save
@gig.user.save
redirect_to @gig.boxlink
else
redirect_to :back, notice: "You don't have enough points"
end
end
end
问题:如何创建一个列出用户下载/购买的页面?
【问题讨论】:
-
你需要注册用户是否下载过东西,然后显示出来
-
例如:1.注册一个下载模型
Download.create(user: current_user, downloadable: thing),2.显示,来自Rails脚手架 -
所以基本上你建议添加到我的“演出”模型中,一个名为“下载”的列,在我的演出模型中,下面(上面的代码),创建类似`def download--- - @gigs = Download.create(user: current_user, download: gig)---end ` 并且在视图中类似于 ?
-
不,不完全是,嗯,我不明白。
-
这是我从您的建议jsfiddle.net/ken1vaqz 中了解到的,请注意我是根据您的建议写的。为了让自己更清楚,我基本上需要保留交易记录,即买家在买东西时制造。
标签: ruby-on-rails ruby ruby-on-rails-4 model-view-controller model