Skip to content

Instantly share code, notes, and snippets.

@mtodd
Forked from nicolasblanco/gist:103748
Created May 1, 2009 00:31
Show Gist options
  • Select an option

  • Save mtodd/104783 to your computer and use it in GitHub Desktop.

Select an option

Save mtodd/104783 to your computer and use it in GitHub Desktop.

Revisions

  1. slainer68 revised this gist Apr 29, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    class ActionController::Request # ActionController::AbstractRequest in Rails < 2.3
    # Test if request seems to come from a bot
    # 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
  2. slainer68 revised this gist Apr 29, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    class ActionController::AbstractRequest # ActionController::Request in Rails 2.3
    class ActionController::Request # ActionController::AbstractRequest in Rails < 2.3
    # Test if 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
  3. slainer68 created this gist Apr 29, 2009.
    13 changes: 13 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    class ActionController::AbstractRequest # ActionController::Request in Rails 2.3
    # Test if 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