title: How to export a HTML file in Rails?
body: <p>I am trying to export links that are in my database into a HTML Netscape Bookmark File using <a href="https://github.com/spajus/markio" rel="nofollow">Markio</a>.</p>
  
  <p>This following Ruby code is from <a href="https://github.com/spajus/markio" rel="nofollow">Markio</a>. I'm not sure how to get it to work with Rails so I can export links from my database to a file the user can download.</p>
  
  <pre><code>builder = Markio::Builder.new
  builder.bookmarks &lt;&lt; Markio::Bookmark.create({
    :title =&gt; "Google",
    :href =&gt; "http://google.com"
  })
  file_contents = builder.build_string
  File.open('/path/to/bookmarks.html', 'w') { |f| f.write file_contents }
  </code></pre>
  
  <p>This is what I have so far in my Rails app. I am most likely going about it completely wrong because I only know how to do it with CSV and Excel. Each Link in my Rails database has a <code>title</code> and a <code>url</code>.</p>
  
  <p>If I navigate to links/export in my browser it should download a file but I get the error "uninitialized constant Markio::Link". </p>
  
  <p>This is my Links controller:</p>
  
  <pre><code>def export
      @links = Link.all
      respond_to do |format|
          format.html { send_data @links.to_csv }
      end
  end
  </code></pre>
  
  <p>This is my Links model:</p>
  
  <pre><code>def self.to_csv(options = {})
      builder = Markio::Builder.new
      builder.bookmarks &lt;&lt; Markio::Link.create({
        :title =&gt; title,
        :href =&gt; url
      })
      file_contents = builder.build_string
      File.open('/path/to/bookmarks.html', 'w') { |f| f.write
      file_contents }
  end
  </code></pre>