I’m on rails and using the pg_search gem.
The search works fine when I’m using an input to pass the param. But when I try to pass the query param from url to my controller to do some advanced filtering, it fails.
The url is something like http://localhost:3000/search?q=new+year, and my controller reads params[:q] as new instead of new year. I’ve been reading the doc and googling for hours but cannot find a solution to my problem.
How can I pass the param with a plus sign from url to controller?
Edit: I pass the param as a hidden field using a form. In my view file:
<% if params[:q] %>
<input name="q" type="hidden" value=<%= params[:q] %>>
<% end %>
This has nothing to do with Rails and parameter parsing; you’re producing malformed HTML. The problem is that you’re missing quotes around your the value of the
valueattribute of your hidden<input>.This:
needs to be this:
Otherwise you’re producing something like
<input ... value=new year />where “year” isn’t parsed as part of thevalueattribute.