Reputation: 3383
I've got a rails 3 app that has ads/specials that are posted on the site by vendors. All of this content is within my site, traffic is not redirected to any external site. I'm trying to institute a pay-per-click system whereby vendors pay per click on deals/specials that belong to them. Ideally for billing I could generate reports on total clicks on a vendors deals during a given period.
Currently I'm using the thumbs_up gem to track favorites/upvotes of vendors by users. Would a similar system be viable for a pay-per-click type arrangment to track number of clicks on a given deal (thumbs_up has a method to only allow one vote per user per instance)? Anyone know of any good gems that already incorporate something like this? Just so I'm clear, I'm not asking for someone to write the code, just looking to get some input from anyone who has either done this before, knows of a good way to accomplish this, or has any other guidance for me. Thanks in advance!
My relevant Vendor model:
class Vendor < ActiveRecord::Base
has_many :deals
acts_as_voteable
end
My relevant Deal model:
class Deal < ActiveRecord::Base
belongs_to :vendor
end
Upvotes: 1
Views: 118
Reputation: 447
Shouldn't be too hard to roll your own, and then it will be easier to customize for your own app.
class Click < Activerecord::Base
belongs_to :deal
belongs_to :vendor, :through => :deal
end
You might consider going polymorphic right from the start, just in case you ever want to track clicks on anything other than deals:
class Click < Activerecord::Base
belongs_to :clickable, :polymorphic => true
belongs_to :vendor, :through => :deal
end
Then just make a pretty simple controller
class ClicksController < ApplicationController
def create
@deal = Deal.find(params[:deal_id])
@deal.clicks.create
redirect_to @deal.url
end
end
This should be a good base for any future functionality.
Upvotes: 1