你好,我有一个 Rails 应用程序,它是一个使用设计、ahoy 和优点的封闭社区。
我们有一个叫做资源的脚手架。每个资源都有一个链接
用户模型
class User < ApplicationRecord
has_merit
has_many :visits, class_name: “Ahoy::Visit”
end
资源模型
class Resource < ApplicationRecord
has_rich_text :description
belongs_to :category
end
控制器
我想使用 Ahoy 跟踪点击链接的用户,以便我可以为访问奖励积分。
看法
<table>
<thead>
<tr>
<th>Title</th>
<th>Link</th>
<th>Category</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @resources.each do |resource| %>
<tr>
<td><%= resource.title %></td>
<td><%= link_to "Learn More", resource.link, class: 'btn btn-dark btn-sm' %></td>
<td><%= resource.category.name %></td>
<td><%= link_to 'Show', resource %></td>
<td><%= link_to 'Edit', edit_resource_path(resource) %></td>
<td><%= link_to 'Destroy', resource, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
架构
create_table "resources", force: :cascade do |t|
t.string "title"
t.string "link"
t.bigint "category_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["category_id"], name: "index_resources_on_category_id"
end
路线
Rails.application.routes.draw do
resources :visits
resources :resources
devise_for :users, controllers: { registrations: 'registrations' }
end
我将如何跟踪链接点击并分配积分?