简体   繁体   English

如何在Rails 4.2.1中使用jquery-addresspicker

[英]How to use jquery-addresspicker in rails 4.2.1

Anyone know how to use it? 有人知道如何使用吗?
I have tried but still fail and in my sources console I get this error 我已经尝试过,但仍然失败,在我的源控制台中,我收到此错误
Uncaught ReferenceError: google is not defined 未捕获的ReferenceError:未定义google

I put the jquery.ui.addresspicker.js in my vendor/assets/javascripts folder 我将jquery.ui.addresspicker.js放在我的vendor / assets / javascripts文件夹中
here is my application.js 这是我的application.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui/datepicker 
//= require bootstrap
//= require turbolinks
//= require underscore
//= require gmaps/google
//= require jquery.ui.addresspicker
//= require_tree .

And I have include googlemaps in my application.html.slim 我在application.html.slim中加入了googlemaps

head
  = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true
  = javascript_include_tag 'application', 'data-turbolinks-track' => true
  script src="//maps.google.com/maps/api/js?sensor=false" type="text/javascript"

I have found the gem but it's not support rails 4 https://github.com/ddidier/address_picker-rails 我已经找到了宝石,但它不支持rails 4 https://github.com/ddidier/address_picker-rails

and here is similar questions but that questions still not show me how to use the jquery-adresspicker How to use jquery-addresspicker jquery with rails 3.1 这是类似的问题,但是这些问题仍然没有告诉我如何使用jquery-adresspicker 如何在rails 3.1中使用jquery-addresspicker jquery

update I try to change the order of script in my application.html.slim and put the googlemaps script first and now I get this error 更新,我尝试更改application.html.slim中脚本的顺序,并先放置googlemaps脚本,现在出现此错误

Uncaught TypeError: $.widget is not a function 未捕获的TypeError:$ .widget不是函数

I have make it work by using bower-rails https://github.com/rharriso/bower-rails/ 我通过使用bower-rails https://github.com/rharriso/bower-rails/使它工作

after the installation via bower-rails 通过凉亭导轨安装后
call the required js to rails asset pipeline (application.js) 调用所需的js到Rails资产管道(application.js)
my application.js 我的application.js

...
//= require typeahead.js/dist/bloodhound.js
//= require typeahead.js/dist/typeahead.jquery.js
//= require typeahead-addresspicker/dist/typeahead-addresspicker.js
//= require_tree .

the rest is just like when u implement it in plain html file 其余的就像当您在纯html文件中实现它时

and if you following the sample code from readme.md and the map is not shown, don't forget to add this to your css file I put it in my Model.scss file 如果您遵循来自readme.md的示例代码并且未显示地图,请不要忘记将其添加到您的css文件中,并将其放入我的Model.scss文件中

#map {
  float:right;
  width: 490px;
  height: 500px;
  border: 1px solid #DDD;
}

There is another gem for this JS library: typeahead-addresspicker-rails . 该JS库还有另一个瑰宝: typeahead-addresspicker-rails Based on the rubygem specs, it looks like it supports Rails 4. 根据rubygem规格,它似乎支持Rails 4。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM