I've just released Rack::DetectTor, Rack middleware for detecting Tor users. It adds an environment varliable
tor_exit_user with a value of
false to the Rack
request object. I've previously blogged about detecting Tor users in nginx using iptables, however Rack::DetectTor is a much neater and more self contained solution for Ruby/Rack based web apps (built on Ruby on Rails, Sinatra, Padrino, etc).
More info on the Github project page: https://github.com/warrenguy/rack-detect-tor
P.S. if you intend to block Tor users, please read this first.