Search code examples
ruby-on-railsrackactioncontroller

Rewrite Rails response URL


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();
})

Solution

  • 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.