I’m trying to create a search field using the form_tag helper. The
problem is when I enter a search, the url_for returns an address such as host.com/search?term=foo. I want to use the format host.com/search/term. I have it set up in routes to recognize the
format search/:term, but form_tag always uses the format host.com/search?term=foo. Does anybody know how to do this?
all I can think of is that order of routes matters, and there may be a
conflict with the default :controller:action scheme. try moving it up
the
list, but be careful that it doesn’t break the rest of your routes.
Well, besides connect being spelt with three n’s I don’ think that
there is anything wrong with your code. And rails is behaving exactly
as expected too.
When the form is created, I believe that rails will generate html like
this (it did when I looked at your code);
So, "term" is supposed to vary depending upon what the user keys in
but then "term" is also supposed to appear into the html before the
user types in anything. I don't think that there is much change of
that working. The URL generated from the form is fine.
http://localhost:3004/products/search?term=something is correct.