开发者

Rails, gmaps4rails don't work with https

I am currently using Rails 3.0.9 and gmaps4rails 0.8.6.

I have a problem with enabling https for google maps.

I tried to use that sollution:

Using gmaps4rails with https/SSL

But with no success.

In layout application I added this js include tags:

<%= javascript_include_tag "https://maps.google.com/maps/api/js?sensor=false&libraries=geometry" %>
<%= javascript_include_tag "https://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/src/infobox.js" %>
<%= javascript_include_tag "gmaps4rails.js" %>
<%= javascript_include_tag "https://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js" %>

My controller code

...
@places = Place.paginate(:page => params[:page], :per_page => 10)
@json = @places.to_gmaps4rails

View

...
 <div id="mapLocal"> <%= gmaps4rails(@json, true false) %> </div>
...

After that google maps still work with http.

Page source code

function gmaps4rails_loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps/api/js?sensor=false&libraries=geometry&callback=gmaps4rails_init";
  document.body.appendChild(script);
}

I tried to change gmaps4rails to gmaps.

Result:

Completed 500 Internal Server Error in 54ms


ActionView::Template::Error (undefined method `to_gmaps4rails' for #<String:0xf5d98528>):
    13: <script type="text/javascript" charset="utf-8">
    14: function gmaps4rails_init() {
    15:     <% #true is passed here to trigger map initialization 开发者_Go百科%>
    16:     <%=raw options.to_gmaps4rails(true) %>
    17: }
    18:   
    19: function gmaps4rails_loadScript() {
  app/views/places/index.html.erb:4:in `_app_views_places_index_html_erb___671263203__86055108_0'

So I decided to upgrade gem(maybe the older version doesn't support ssl?).

After upgrade from 0.8.6 to 1.1.4 map isn't even generated with my basic, unchanged code

  <div id="mapLocal"> <%= gmaps4rails(@json) %> </div>

I checked js logs with firebug and it returns

Gmaps4RailsGoogle is not defined
Gmaps.map = new Gmaps4RailsGoogle(); 


You should upgrade to the latest version of the gem: Gmaps4RailsGoogle didn't exist in 0.x.x.

Using 1.x.x, you'll need to require an additional file:

gmaps4rails.googlemaps.js

And 'gmaps4rails.js' is now 'gmaps4rails.base.js'

Using the installer, you'll have everything copied.

When using the gmaps helper, you need to provide a hash as first argument:

gmaps( :markers => { :data => @json } )

Some changes where necessary when coding 1.0.0, cause now multiple maps can be created on the same page. Anyway, all doc is in the wiki. I guess all these indications answer your need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜