How to upload image into Gmaps4rails's marker using Paperclip?

169 views Asked by At

I'm currently using paperclip gem to upload users profile_image. I'm also using gmaps4rails for google map which shows users' location and info on markers. Everything works fine except that I'm not sure how to upload user's profile_image on the marker. Here's what I have:

in a normal user view page the following code shows a user's profile image:

<%= image_tag user.profile_image.url(:thumb)%>

I tried to use the above code in the controller but it doesn't seem to work

user controller:

  @hash = Gmaps4rails.build_markers(@nearby) do |user, marker|
          marker.lat user.latitude
          marker.lng user.longitude
          marker.infowindow user.name
          marker.picture({
              "url" => "<%=image_tag user.profile_pic.url(:thumb)%>",
              "width" => 36,
              "height" => 36
            }) 
          end     

After I added the marker.picture the map is still there but the markers have disappeared

in user view:

handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, 
    function(){
      markers = handler.addMarkers(<%=raw @hash.to_json %>);
      handler.bounds.extendWith(markers);
      handler.fitMapToBounds();
    });

Any suggestions/solution or if you could point me to the right direction would be greatly appreciated!

1

There are 1 answers

0
apneadiving On BEST ANSWER

You should replace:

"url" => "<%=image_tag user.profile_pic.url(:thumb)%>",

With:

"url" => user.profile_pic.url(:thumb),

Only the url is required