summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/json_file.rb
blob: 0cb4b6d385176951613705ed79a793784156b850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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