title: Ruby on Rails: How to render file as plain text (without any HTML)
body: <p>How do you render file as a plain/text in rails (without rendering any HTML)?</p>
  
  <p>I've tried:</p>
  
  <pre><code>render file: "path/to/file", layout: false
  </code></pre>
  
  <p>and</p>
  
  <pre><code>render file: "path/to/file", content_type: 'text/plain'
  </code></pre>
  
  <p>also both</p>
  
  <pre><code>render file: "path/to/file", layout: false, content_type: 'text/plain'
  </code></pre>
  
  <p>But there still some html on the response.</p>
  
  <p>I'm using rails 3.2.14 and ruby 1.9.3</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Silly me, this actually works:</p>
  
  <pre><code>render file: "path/to/file", layout: false, content_type: 'text/plain'
  </code></pre>
  
  <p>I was inspecting the element using google chrome, so there's an html tag appears. But when I see the source, there's no HTML tag.</p>
  
  <p>The file I was trying to render is a custom made file without extension, it is a tab separated value I use as a parameter in d3.tsv() (D3.js)</p>
  
  <p>Thank you all for your efforts. :D</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>In Edit 1, I checked the response and it's true that it doesn't come with any html tag. But using it as parameter in d3.tsv() (D3.js) doesn't work apparently. Glad I tried <a href="https://stackoverflow.com/a/21129848/881272">the answer</a> from <a href="https://stackoverflow.com/users/380733/jetabe">JetAbe</a> and it works! So I accepted JetAbe's answer.</p>