Clearing GET parameters in links

I have a template like this

<ul>
  <li><%= link "Any", to: Routes.page_path(@conn, :index, Map.delete(@conn.params, :author)) %></li>
  <%= for {label, key} <- author do %>
    <li><%= link label, to: Routes.page_path(@conn, :index, Map.put(@conn.params, :author, key)) %></li>
  <% end %>
</ul>

for the user to quickly list only pages by certain authors. The first link with the “Any” label is meant to clear the “author” GET parameter, to list all pages, but the route helper just returns a path with the current value of the “author” GET parameter.

How can I clear this GET parameter completely?

Check if the keys of the params map are indeed of type :atom and not :string. Most likely they are strings, in which case Map.delete(@conn.params, "author") should do it.

2 Likes

That did the trick, thanks!