title: Separating an Array into a comma separated string with quotes
body: <p>I'm manually building an SQL query where I'm using an Array in the params hash for an SQL IN statement, like: ("WHERE my_field IN('blue','green','red')").   So I need to take the contents of the array and output them into a string where each element is single quoted and comma separated (and with no ending comma).</p>
  
  <p>So if the array was: <code>my_array = ['blue','green','red']</code></p>
  
  <p>I'd need a string that looked like: <code>"'blue','green','red'"</code></p>
  
  <p>I'm pretty new to Ruby/Rails but came up with something that worked:</p>
  
  <pre><code>if !params[:colors].nil?
     @categories_array = params[:colors][:categories]
     @categories_string =""
     for x in @categories_array
        @categories_string += "'" + x + "',"
     end
     @categories_string.chop!     #remove the last comma
  end
  </code></pre>
  
  <p>So, I'm good but curious as to what a proper and more consise way of doing this would look like?</p>