Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6046781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:16:45+00:00 2026-05-23T07:16:45+00:00

There are topics that try to cover this here: Gmaps4rails : map not showing

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:16:45+00:00Added an answer on May 23, 2026 at 7:16 am

    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:

    //include google script
    <script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=geometry'></script>
    //include gmaps4rails javascript
    <%=javascript_include_tag 'gmaps4rails' %>
    
    <script type="text/javascript" charset="utf-8">
    //load map when button click (replace with what you want)
    $('#ajax_map').click(function(){
      //you have to set a size to the div otherwise the map won't display, that's the purpose of these css classes
      $('#map_container').addClass('map_container');
      $('#gmaps4rails_map').addClass('gmaps4rails_map');
      //create the map object
      Gmaps4Rails.initialize();
      //of course, replace these two with your dynamic data, you'd have to use some $.ajax jQuery method.
      Gmaps4Rails.direction_conf.origin = 'toulon, france';
      Gmaps4Rails.direction_conf.destination = 'paris, france';
      //read the js file, you can customize much more: https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/public/javascripts/gmaps4rails.js
      Gmaps4Rails.create_direction();
    });
    </script>
    
    <div id="map_container"> 
      <div id="gmaps4rails_map"></div>
    </div>
    
    <button type="button" id="ajax_map">Ajax Map</button>
    

    Add the following class in your CSS:

    #map-container {
      width: 800px;
    }
    
    #gmaps4rails_map {
      width: 800px;
      height: 400px;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are some topics about this here already but I could not
The current situation is that topics are sorted by 3 main categories. There is
It's my first question on SO. I know that there were many topics on
First. I know that there already exists a variety of topics on how to
I know that there are many different questions about this sort of topic on
Okay, I browsed through a few topics here, but there was no definite answer.
First off I apologize if there is another post out there that answers this,
I maintain a Python program that provides advice on certain topics. It does this
I know that there has to be quite a lot of documentation about this
I know there is a couple of topics about that, but the reason I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.