I have a file on my server that is outside of my application directory. This is a text file containing a json object, /path/to/data.json
.
What is the easiest way to serve this file in Rails, for example. return it in response to a GET request?
Here is what I have tried so far, inspired by this answer and others. (It may be off base - I'm new to rails.)
class DataController < ApplicationController
@data = File.read("/path/to/data.json") def index render :json => @data end end
This does not work. When I point my browser to http://myserver.com/data.json , I just see "null" instead of the data.json
file.
Any idea what I'm doing wrong?
source share