I want to render the map only on demand(to minimize the loading time), means some link like 'Show Map' should render the map in a specified div. what should i do?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Simply use the 'to_gmaps4rails' method described here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Methods
Basically, do:
<%=raw assets_hash.to_gmaps4rails(true) %>
This will render only the js necessary to display your assets.
So include gmaps4rails.js and .css (if necessary), and the div to host the map.