0
私のアプリでGoogleの場所を使用しています。すべて正常に動作しますが、入力から国を削除または無視したいだけです。Google place autocomplete remove country to query
例えばそれが入力した場合、 "アーク" 私は私が欲しい私はこのquery=Arcachon%2C+France
のようなクエリを持ってクリックした後
Arcachon, France Arcueil, France Archamps, France
...
を持っているだけで、このquery=Arcachon
と削除または無視%2C+France
<%= form_tag(result_path, method: :get) %>
<%= text_field_tag :query, params[:query], class:"search-query form-control", placeholder:"Ex: Corse, Arcachon..." %>
<%= submit_tag "Partez", class:"btn btn-danger", name: nil %>
<script>
function init() {
var options = {
types: ['(cities)'],
componentRestrictions: {country: "fr"}};
var input = document.getElementById('query');
var autocomplete = new google.maps.places.Autocomplete(input, options);}
google.maps.event.addDomListener(window, 'load', init);
</script>
で
私のjs model.rbからの私のクエリあなたの助けを
def self.search(query)
return scoped unless query.present?
where(['nomdep LIKE ? OR name LIKE ? OR nomregion LIKE ? OR commune LIKE?', "%#{query.mb_chars.downcase}%", "%#{query.mb_chars.downcase}%", "%#{query.mb_chars.downcase}%", "%#{query.mb_chars.downcase}%"])
end
とコントローラ
def result
if params[:query].blank?
redirect_to action: :index and return
else
@campings = Camping.search(params[:query])
end
end
感謝。