简体   繁体   中英

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

I put the jquery.ui.addresspicker.js in my vendor/assets/javascripts folder
here is my 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

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

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

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

Uncaught TypeError: $.widget is not a function

I have make it work by using bower-rails https://github.com/rharriso/bower-rails/

after the installation via bower-rails
call the required js to rails asset pipeline (application.js)
my 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

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

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

There is another gem for this JS library: typeahead-addresspicker-rails . Based on the rubygem specs, it looks like it supports Rails 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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