title: How to serve a static JSON file in rails?
body: <p>I have a file on my server that's outside of my app directory. It's a text file that holds a json object, <code>/path/to/data.json</code>.</p>
  <p>What's the simplest way to serve this file in Rails, e.g. to return it in response to a GET request?</p>
  <p>Here's what I've tried so far, inspired by <a href="https://stackoverflow.com/questions/9348712/serve-a-static-json-object-file-in-rails">this answer</a> and others. (This may be way off-base -- I'm new to rails.)</p>
  <ol>
  <li><p>added this line to routes.rb
  <code>  resources :data</code></p>
  </li>
  <li><p>Wrote the following data_controller.rb</p>
  </li>
  </ol>
  <p><code>class DataController &lt; ApplicationController</code></p>
  <pre><code>@data = File.read(&quot;/path/to/data.json&quot;)
  
  def index
    render :json =&gt; @data
   end
  end
  </code></pre>
  <p>This doesn't work.  When I direct my browser to <a href="http://myserver.com/data.json" rel="noreferrer">http://myserver.com/data.json</a>  I just see &quot;null&quot; instead of the <code>data.json</code> file.</p>
  <p>Any idea what I'm doing wrong?</p>