title: Rails - How do I 'merge' or append a value to an array within the URL?
body: <p>I am trying to pass an array in the URL, which is working fine, but I'd like to know how I can then insert or remove certain values?</p>
  
  <p>For example, I have a link that looks like:</p>
  
  <pre><code>http://localhost:3000/pins?genre_ids[]=1,2,3
  </code></pre>
  
  <p>I would like to build a set of links that can insert or remove numbers from this URL array.</p>
  
  <p>At the moment, each link I have simply changes the genre_ids[] value completely, where as I'd like to add to it, or take away as needed. This is my code to build the link...</p>
  
  <pre><code>&lt;%= link_to genre[0].title, pins_path( params.merge({ :genre_ids =&gt; [genre[0].id] }) ) %&gt;
  </code></pre>
  
  <p>I think what I'm after is something like <code>params.merge()</code> but for the value of <code>params[:genre_ids]</code></p>
  
  <p>I hope you can understand what I mean? If the current URL reads <code>/pins?genre_ids[]=1,2,3</code> I'd like it so that each link I build includes this current link, with the addition of another number into this array, so that it would look like <code>/pins?genre_ids[]=1,2,3,4</code></p>
  
  <p>Any help would be greatly appreciated. I'm from a CF background, so I'm still trying to get my head around Ruby and Rails. I am using Rails 4 with Ruby 2.</p>
  
  <p>Thanks,
  Michael.</p>