百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

punching_bag

> 编程语言
开源

Punching Bag 是一个针对 Ruby on Rails 的点击跟踪插件,专注于简单的趋势分析。

100 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Punching Bag 是一个针对 Ruby on Rails 的点击跟踪插件,专注于简单的趋势分析。

Punching Bag

Punching Bag is a hit tracking plugin for Ruby on Rails that specializes in simple trending.

Features

  • Total hit count
  • Hit counts for the last day, week, month, etc.
  • Simple trending based on most hits in the last day, week, month, etc.
  • Rake task to group old hit records for better performance
  • ActsAsTaggableOn integration for trending tags/topics support
  • Voight-Kampff integration for bot checking

Requirements

  • An existing Rails app
  • Ruby >= 2.3

Installation

In your Gemfile add:

gem "punching_bag"

In the terminal run:

bundle install
rails g punching_bag
rake db:migrate

In your model add:

acts_as_punchable

Usage

Tracking hits in your controller

class PostsController < ApplicationController
  def show
    @post.punch(request)
  end
end

Getting a total hit count in your view

@post.hits

Getting a hit count for a time period in your view

@post.hits(1.week.ago)

Getting a list of the five all-time most hit posts

Post.most_hit

Getting a list of the 10 most hit posts for the last 24 hours

Post.most_hit(1.day.ago, 10)  # limit is 5 by default, pass nil for no limits

Sorting posts based on all time hit count

Post.sort_by_popularity('DESC')   # DESC by default, can also use ASC

Getting a hit count on a tag for the last month

tag.hits(1.month.ago)

Getting a list of the 10 most hit tags in the last week

ActsAsTaggableOn::Tag.most_hit(1.month.ago, 10)

Compressing old hit records to improve performance
The default settings combine records by day if they're older than 7 days, by month if they're older than 1 month and by year if they're older than 1 year

rake punching_bag:combine

Compressing old hit records using custom settings
This time we'll combine records by day if they're older than 14 days, by month if they're older than 3 months and by year if they're older than 2 years

rake punching_bag:combine[14,3,2]

Notes

  • The punching_bag:combine rake tasks is not run automatically. You'll have to run it manually or add it as a cron job.
  • The punching_bag:combine rake task can take a while depending on how many records need to be combined.
  • Passing the request object to the punch method is optional but without it requests from bots, crawlers and spiders will be tracked.
  • See the Voight-Kampff documentation if you'd like to customize the list of user-agents considered bots.
  • The tag related features will only work if you have ActsAsTaggableOn installed and enabled on the same models as Punching Bag.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言