Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created April 29, 2009 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nicolasblanco/103748 to your computer and use it in GitHub Desktop.
Save nicolasblanco/103748 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