Created
April 29, 2009 12:40
-
-
Save nicolasblanco/103748 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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