Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The relavent code you're looking to modify is is the snippet below, where <code>content</code> is getting assigned to whatever will show up in the infowindow when it's clicked on.</p> <pre><code>var infowindow = new google.maps.InfoWindow({ content: business.business_name + '&lt;br/&gt;' + 'Phone: ' + business.phone }); </code></pre> <p>The trick is going to be building the URL, since the JavaScript has no knowledge of Rails routes. You could change the controller's <a href="http://edgeapi.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html#method-i-as_json" rel="nofollow">JSON rendering</a> to include the URL perhaps adding <code>:methods =&gt; [:to_param]</code> <em>(the better way)</em> OR build a compatible URL in javascript <em>(the easy way)</em> and hoping that whatever parses the URLs only uses the integers.</p> <hr> <p><strong>Easy Way</strong></p> <p>In the view -</p> <pre><code>var infowindow = new google.maps.InfoWindow({ content: '&lt;a href="/businesses/' + business.id + '"&gt;' + business.business_name + '&lt;/a&gt;&lt;br/&gt;' + 'Phone: ' + business.phone }); </code></pre> <hr> <p><strong>Slightly Better Way</strong></p> <p>In the controller - </p> <pre><code>format.json { render :json =&gt; @businesses.to_json(:only =&gt; [:id, :business_name, :phone, :latitude, :longitude], :methods =&gt; [:to_param]) } </code></pre> <p>In the view -</p> <pre><code>var infowindow = new google.maps.InfoWindow({ content: '&lt;a href="/businesses/' + business.to_param + '"&gt;' + business.business_name + '&lt;/a&gt;&lt;br/&gt;' + 'Phone: ' + business.phone }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload