summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/json_file.rb
blob: 5b5e55ec45dac98925eed42b3c10c2a3f7193699 (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.exist?(@filename)
      @file = File.new(@filename)
    else
      not_found
    end
  end

end