Friday, 12 July 2013

Make robots.txt environment-aware in Rails

In home_controller.rb:
  def robots
    robots = File.read(Rails.root + "config/robots.#{Rails.env}.txt")
    render :text => robots, :layout => false, :content_type => "text/plain"
  end
In routes.rb:
  get "/robots.txt" => "home#robots"
And create robots.production.txt, robots.development.txt in your config directory as you wish

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!