0

I saw this.

I did params.select!{|k, v| v.present?} which cleans blank params, but I do not know how to make the response URL to be cleaned.

I continue getting something like http://localhost:3000/restaurants/search?utf8=%E2%9C%93&city=&cuisine=&number_of_people=&query=hello

I am looking for http://localhost:3000/restaurants/search?utf8=%E2%9C%93&query=hello

Also, I would delete utf8 param, is that bad?

Update

I am considering a JavaScript solution, but I think this should be on the server:

$('form').submit(function(e){
  e.preventDefault();
  // clean params, anyway is hard for me to figure this part out
  $(this).submit();
})
Community
  • 1
  • 1
sites
  • 21,417
  • 17
  • 87
  • 146
  • I think you have to redirect to the same URL, but with the filtered parameters. So probably check if filtering the parameters actually omits anything, and if it does, redirect to the same URL with the filtered parameters. – Tamer Shlash Jun 03 '15 at 22:54
  • Are you redirecting the user? I don't understand where you want to rewrite the url. – Philip Hallstrom Jun 03 '15 at 22:55
  • I was thinking that redirecting is not what I want, I want to rewrite the response URL without making a second request. Redirecting makes a second request, right? – sites Jun 03 '15 at 22:57
  • all of this is for setting `link rel='next/prev'` for SEO, maybe I am complicating things, and I should just leave the the blank params, what do you think? – sites Jun 03 '15 at 22:58

1 Answers1

0

My solution was to disable blank inputs and selects:

$('form').submit (e) ->
  $(@).find('select,input').map( (i, e) -> e.disabled = !$(e).val() )

Regarding removing utf8 I found this. So I better keep sending it.

Community
  • 1
  • 1
sites
  • 21,417
  • 17
  • 87
  • 146