How to add link_to to select_tag with Rails / ERB?

I have the following code in my index.html.erb

<%= select_tag 'team_id', options_for_select(@teams.map{|team| ["#{team.name} # {team.nick}", team.id] }) %> 

Where would I add the helper link_to element inside this block? Is it possible to add link_to for select_tag?

The desired link_to will go to '/ Teamleader / ID_OF_OPTION_PICKED'

UPDATE:

To be more clear; when the user selects a parameter from the select tag, I want to redirect the page to the desired link (from link_to).

+6
source share
2 answers
 <%= select_tag 'team_id', options_from_collection_for_select(@teams, "id", "name") %> <script> $(function(){ $('#team_id').bind('change', function () { var url = "/Teamleader/" + $(this).val() if (url) { window.location.replace(url); } return false; }); }); </script> 
+6
source

Try:

 <%= select_tag 'team_id', options_from_collection_for_select(@teams, "id", "name"),:onchange => "window.location.replace('/Teamleader/'+this.value);" %> 
+5
source

All Articles