I want to use a select menu to redirect to another page but when I select ‘Home’ it doesn’t redirect me to the main page. Nothing happens…
<select>
<option>Select a menu</option>
<option><%= link_to 'Home', '/' %></option>
</select>
Thank you for your help.
The
link_tohelper outputs an HTML hyperlink which is not going to work when nested within anoptionelement. You should change your options so that they have this format:Then you could have some JavaScript that observes the
onchangeevent of the dropdown and sets thedocument.location.hrefto the value of the selected option. This will perform the redirect.Alternatively, you could have a Go submit button next to the dropdown that submits the form and then have Rails perform a server-side redirect to the page for the selected option using the
redirect_tohelper.