summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/json_file.rb
blob: 6be919a358097048d72ed3ec1d8788be1c2aa0e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module ControllerExtension::JsonFile
  extend ActiveSupport::Concern
  include ControllerExtension::Errors

  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