title: How to serve static content from a controller in Rails?
body: <p>I'd like to serve static content from a controller action in Rails the same way that Rails serves static content out of the public directory. I do not want to just change the path of the public directory or add another path to Rails to serve files from there. I want to explicitly handle requests to specific files in a controller to verify the request depending on the requested files.</p>
  
  <p>I naively tried to use <code>send_file</code> but then I can not use range requests anymore.</p>
  
  <pre><code>class MyController &lt; ApplicationController
    def dummyAction
      filePath = 'foo/bar/baz.mp3'
      send_file(filePath, {:filename =&gt; "baz.mp3", :type =&gt; "audio/mpeg"})
    end
  end
  </code></pre>
  
  <p>I'd prefer to use Rails instead of writing all the code myself. Is there something in Rails to do this? Maybe a Gem?</p>