title: How do I create a temp file and write to it then allow users to download it?
body: <p>I'm working on my first application and I need some help with allowing my users to download a text file with certain variables that are being displayed on the page.</p>
  
  <p>Take a shopping list for example.
  Let's say you allow your users to create a shopping list of products, and then display the shopping list with the items on a shopping list page,
  <br> <strong>e.g. localhost:3000/list/my-list</strong></p>
  
  <p><br>
  Take a look at the example code below (which is probably incorrect):</p>
  
  <pre><code>File.open('shopping_list.txt', 'w') do |file|
    file.puts 'Item 1: #{product_1.name}'
    file.puts 'Item 2: #{product_2.name}'
    file.puts 'Item 3: #{product_3.name}'
  end
  </code></pre>
  
  <p><br><br>
  Which then creates a text file that has the following content:</p>
  
  <pre><code>Item 1: Eggs
  Item 2: Butter
  Item 3: Bread
  </code></pre>
  
  <p><br>Users should then be able to download this file (i don't want this file to be stored on the server) via a download link.</p>
  
  <p>I have no idea how to achieve this, but I'm hoping you guys can guide me. :D</p>
  
  <p><br><strong>TL;DR</strong></p>
  
  <ul>
  <li>create text files populated with model data (perhaps create a method to achieve this?)</li>
  <li>text files should not be stored on the server, but created as users click the download button (not sure if this is the rails way but perhaps someone could show me a better way)</li>
  </ul>