Let’s say I need a simple search form:
<form action="<%= search_path %>" methode="GET">
<input type="text" placeholder="where?" name="place_name" />
</form>
I need to generate a url based on the input field so I can show:
/search/some-value
I tried:
match 'search(/:place_name)', to: 'some_controller#some_action', as: 'search'
Any suggestions why it’s not working or what I’m doing wrong here?
If you submit a form, the parameters set via inputs within the form will be appended to the URL using query parameters — in your case that would look something like this:
That’s the basic form behavior and there’s no easy way around this unless you want to use some Javascript to handle the request (which I would advice against in this case).
To use the default behavior however, your route would need to look like this:
The parameter
place_namewill then be available in the controller using:Hope this helps.