There are topics that try to cover this here: Gmaps4rails : map not showing when loaded dynamically and especially here: Rendering google map using gmaps4rails through Ajax, also watched the screencast in which a gmap is dynamically updated but I still don't seem to get it work.
I am trying to load the map in a drop-down tab only if a button is clicked displaying the direction between a user and an offer. In my _location.html.erb partial I have:
<%= gmaps({ "direction" => { "data" => { "from" => current_user.location, "to" => @offer.location } } })%>
(the locations are addresses)
Now this works nicely when the partial is rendered immediately. If I however try to render the partial over an AJAX call later after the whole page has already loaded initially, the gmap is not displayed. Is it possible to initialize and render the gmap through an AJAX call and display directions then?
The reason is quite simple: the partial contains much javascript you can't load and execute this way.
So you can't use RJS there.
The proper way to do is UJS: get data with an AJAX call and render the result. In the following code, I use jQuery.
In your view add:
Add the following class in your CSS: