From 81ce6ed8a368f9ee9e01412464cbede75369ed37 Mon Sep 17 00:00:00 2001 From: Jake Yesbeck Date: Tue, 5 May 2015 08:58:33 -0700 Subject: [PATCH] Make sure file exists before attempting to render it --- app/controllers/robots_controller.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/robots_controller.rb b/app/controllers/robots_controller.rb index 34e07d646..785c8a856 100644 --- a/app/controllers/robots_controller.rb +++ b/app/controllers/robots_controller.rb @@ -1,13 +1,17 @@ class RobotsController < ApplicationController def robots - subdomain = request.subdomain - - filename = if subdomain.present? && subdomain != 'www' - "robots.#{ subdomain }.txt" - else - "robots.txt" + filename = if subdomain && subdomain != 'www' + "config/robots.#{ subdomain }.txt" end - render file: "config/#{ filename }", layout: false, content_type: 'text/plain' + file_to_render = File.exists?(filename.to_s) ? filename : 'config/robots.txt' + + render file: file_to_render, layout: false, content_type: 'text/plain' + end + + private + + def subdomain + request.subdomain.present? ? request.subdomain : nil end end