Thursday, May 29, 2008

Disable rails session for robot (search engine crawler)

class ApplicationController < ActionController::Base
session :off, :if => lambda {|req| req.user_agent = ~/(Google|Slurp)/i}
# Google for Google and Slurp for Yahoo!.
# Explore your log for more robots

* Cited from The Rails Way

1 comment:

Jaap said...

There's a Ruby GEM that helps figuring out which UA strings belongs to a robot

http://github.com/jaap3/urobot/tree/master