我有这个rails-jquery-autocomplete表单,效果很好,但我想立即将用户引导到城市展示页面
<%= form_tag(cits_path, :method => "get", id: "search-form", class: "form-inline") do %>
<%= autocomplete_field_tag :search, params[:search], autocomplete_cit_name_events_path,
{class: "form-control", type: "search", 'data-auto-focus' => true} %>
<%= submit_tag "#{t "navlinks.search"}", {class: "btn btn-default"} %>
<% end %>
<script type="text/javascript" charset="utf-8">
$('#search').bind('railsAutocomplete.select', function(event, data){
$('#search-form').submit()
});
</script>
将用户带到:
/ CITS UTF8 =✓&安培;搜索=布达佩斯
我希望用户到达这里:
/ CITS /布达佩斯
引用方式如下:cit_path(cit.name)
这里需要什么魔法? :)
答案 0 :(得分:1)
您只需更改当前位置,而不是提交表单 示例:
$('#search').bind('railsAutocomplete.select', function(event, data) {
//First you need to get the City.
var city = data.item.value; //or whatever key to grab the city
//do the redirect
window.location = '/cits/' + city;
});