あなたができることは、各Product
モデルにhave_many
承認されたユーザーを持たせることです。BrainTreeが、ユーザーが製品に対して支払ったOKを提供する場合、そのユーザーを承認済みユーザーリストに追加できます。したがってProductController
、current_userが承認されたユーザーであるかどうかを確認し、承認されている場合はファイルをダウンロードし、そうでない場合はリダイレクトします。
Exsampleの場合:
product.rb
class Product < ActiveRecord::Model
has_many approved_users, :class => User
end
product_controller.rb
class ProductController
def download
@product = Product.find_by_id(:id)
if @product.approved_users.includes?(current_user)
# Give them the file
else
flash[:notice] = "You must buy the product first!"
redirect_to product_sales_url(@product)
end
end
end
またはそのようなもの。私の構文は少しずれているかもしれませんが、これでうまくいくはずです。