summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/controller_extension')
-rw-r--r--app/controllers/controller_extension/json_file.rb22
1 files changed, 22 insertions, 0 deletions
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
+