Improving the search

:  ~ 45 sec read

I wanted a visual representation and helper for the user when a search is performed on the site. So I thought about autocompleting the searched term in the search field. At first I tried with jQuery:

var query = decodeURIComponent(location.search)
  .split("=")[1]
  .replace(/[\+]/g, " ");
$('input.search').val(query);
$('input.banner-search').val(query);

But this had a small delay and the slight inconvenience of having to replace + with a space, and to decode the URL. So I ended up with some really simple ruby, inside layout.erb:

<% query_params = request.params['query'] %>
<input type="text" [...] value='<%= query_params %>'/>