Jul 22, 2015:  ~ 1 min read

Improving the search

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)
  .replace(/[\+]/g, " ");

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 %>'/>
Subscribe to my monthly newsletter.
No spam, unsubscribe at any time.