title: Rails: CSV Array to string (convert)
body: <p>I am new to rails and I would like to export a dictionary (of strings). 
  At the moment I am using this piece of code</p>
  
  <pre><code>    Competency.order(:competencies).map(&amp;:competencies).uniq!.join(", ")
  </code></pre>
  
  <p>To generate:</p>
  
  <pre><code>   Build a cage!, Build tha pizza, Demonstrated ability in flying, Demonstrated ability in pizza baking
  </code></pre>
  
  <p>I would like to export this to csv, however the problem is that it is one array. I would like to create separate strings (comma separated) and displaying each string on a different row. Currently everything is displayed on one row when exporting this to csv. </p>
  
  <p>Any clue how to do this? I created an array of the data because there is a lot of duplicate data and this piece of code is filtering all the duplicates out.</p>
  
  <p>In my controller:</p>
  
  <pre><code>   format.csv { render Competency.order(:competencies).map(&amp;:competencies).uniq!.join(", ") }
  </code></pre>
  
  <p>I hope anyone could help me, much appreciated.</p>
  
  <p>Edit:</p>
  
  <p>Ideally I would like to fetch all competencies and have an output without duplicates, this is my controller:</p>
  
  <pre><code>    def dictionary
        @competencies = Competency.all
  
          respond_to do |format|
          format.html { render html: positions_dictionary_path }
          format.csv { render Competency.order(:competencies).map(&amp;:competencies).uniq!.join(", ") }
          format.xls { send_data Competency.order(:competencies).map(&amp;:competencies).uniq!.join(", ") }
  
        end
      end
  </code></pre>
  
  <p>Usually in a view file you would do:</p>
  
  <pre><code>      &lt;div&gt;
          &lt;% @posts.each do |competency| %&gt;
            &lt;%= competency.competencies %&gt;
          &lt;% end %&gt;
        &lt;/div&gt;
  </code></pre>
  
  <p>This generates a list of all the competencies, however also the duplicates. My solution was to create an array. However this creates problems when exporting to csv (because I need every output on a different line/row. So my question, how can I generate a list of all the "competencies" without duplicates?</p>