Добавьте это в свой ApplicationController (app/controllers/application_controller.rb
):
before_filter :count_hits
def count_hits
# This tries to find a existing PageHit by the given url. If it does
# not find one, it creates one.
@hit = PageHit.find_or_create_by_url(request.url)
# Issues an UPDATE page_hits WHERE id = 123 SET count = count + 1
# on the underlying database layer. This atomically increments, so
# you do not run into race conditions.
PageHit.increment_counter(:count, @hit.id)
end
Убедитесь, что вы создали модель PageHit
, содержащую строку URL и целое число.