html+link+点击次数,计算单击链接的次数

所以我试图记录链接被点击但无法克服最后一道障碍的次数。

到目前为止,我有以下内容:

配置/ routes.rb中

resources :papers do

resources :articles do

resources :clicks

end

end

click.rb

class Click < ActiveRecord::Base

belongs_to :article, counter_cache: true

validates :ip_address, uniqueness: {scope: :article_id}

end

clicks_controller.rb

class ClicksController&lt; ApplicationController中

def create

@article = Article.find(params[:article_id])

@click = @article.clicks.new(ip_address: request.ip)

@click.save

end

end

article.rb

class Article < ActiveRecord::Base

has_many :clicks

end

schema.rb

create_table "clicks", force: true do |t|

t.integer "article_id"

t.string "ip_address"

t.datetime "created_at"

t.datetime "updated_at"

end

create_table "articles", force: true do |t|

t.datetime "created_at"

t.datetime "updated_at"

t.text "title"

t.string "url"

t.integer "paper_id"

t.integer "clicks_count"

end

index.html.erb - 文章

首先,这个设置看起来是否正确,有人看到我可能出错的地方吗?

其次,我不知道如何设置我的视图,以便在点击现有链接时注册点击并且计数上升?

由于

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值