我有下面的代码在我的index.html.erb
<%= select_tag 'team_id', options_for_select(@teams.map{|team| ["#{team.name} #
{team.nick}", team.id] }) %>
我会在哪里添加块内的link_to助手? 我甚至可以添加对select_tag一个的link_to?
所需的link_to会去“/ Teamleader / ID_OF_OPTION_PICKED”
更新:
为了更清晰; 当用户选择从选择标签的选项,我想在页面重定向到所需的链接(来自的link_to)。
<%= 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>
尝试:
<%= select_tag 'team_id', options_from_collection_for_select(@teams, "id", "name"),:onchange => "window.location.replace('/Teamleader/'+this.value);" %>