I am trying to build a page that displays a list of categories. When you click on one of them, you are taken to the same page but now with a new query string of the category you just selected. You can then select another category, allowing them to stack. The URL may eventually look like this. 

```ruby
http://localhost:3000/filter?categories%5B%5D=restaurant&categories%5B%5D=takeout

```

In my Rails View, I'm using a `link_to` to build these URLs. When there isn't an existing category in the query string, I simply pass the Categories symbol and a single array of the category in questions permalink. When there is an existing category, I want to insert the new category into the `request.query_parameters` categories array, and then merge it with request.query\_parameters as a whole. This is so I can also have subcategories and order/sort queries in the future too.

```ruby
<% @categories.each do |category| %>

    <% if !params.has_key?(:categories) %>
        <%= link_to category.category_name, shops_path(categories: [category.permalink]) %>
    <% else %>
        <%= link_to category.category_name, shops_path(request.query_parameters.merge(request.query_parameters[:categories] << category.permalink)) %>
    <% end %>

<% end %>

```

I will then use the permalinks to search my database for Categories with matching permalinks, and display my results that match at least one of any of the categories from the query string in the URL.

Clicking on the first link creates a hash like this for request.query\_parameters from the following URL.

```ruby
{"categories"=>["restaurant"]}
http://localhost:3000/filter?categories%5B%5D=restaurant

```

And I would exepct the second like to create a hash like this, from the following URL.

```ruby
{"categories"=>["restaurant","takeout"]}
http://localhost:3000/filter?categories%5B%5D=restaurant&categories%5B%5D=takeout

```

However, I recieve the following error message.

```ruby
undefined method `to_hash' for ["restaurant", "takeout"]:Array
Did you mean?  to_h

Request
Parameters:

{"categories"=>["restaurant", "takeout"]}

```

How can I get round this error?

**Edit**

Found a solution, so posted it as an answer.