Skip to content

Instantly share code, notes, and snippets.

@mtodd
Forked from nicolasblanco/gist:103748
Created May 1, 2009 00:31
Show Gist options
  • Save mtodd/104783 to your computer and use it in GitHub Desktop.
Save mtodd/104783 to your computer and use it in GitHub Desktop.
class ActionController::Request # ActionController::AbstractRequest in Rails < 2.3
# Returns true if the request seems to come from a bot
def bot?
user_agent =~ /\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg)\b/i
end
end
#
# Then in your controllers you can do :
#
# unless request.bot?
# ... Log, stat ...
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment