From f07c952c870bfb8634ef0d80737b67a1eec760f6 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 14 Jul 2014 13:04:30 +0200 Subject: send config files from ConfigsController --- app/controllers/controller_extension/json_file.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/controllers/controller_extension/json_file.rb (limited to 'app/controllers/controller_extension') diff --git a/app/controllers/controller_extension/json_file.rb b/app/controllers/controller_extension/json_file.rb new file mode 100644 index 0000000..0cb4b6d --- /dev/null +++ b/app/controllers/controller_extension/json_file.rb @@ -0,0 +1,22 @@ +module ControllerExtension::JsonFile + extend ActiveSupport::Concern + + protected + + def send_file + if stale?(:last_modified => @file.mtime) + response.content_type = 'application/json' + render :text => @file.read + end + end + + def fetch_file + if File.exists?(@filename) + @file = File.new(@filename) + else + not_found + end + end + +end + -- cgit v1.2.3