<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - How to call a rails method from javascript (googlemaps)]]></title>
		<link>http://railsforum.com/viewtopic.php?id=39809</link>
		<description><![CDATA[The most recent posts in How to call a rails method from javascript (googlemaps).]]></description>
		<lastBuildDate>Sun, 04 Jul 2010 16:26:31 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[How to call a rails method from javascript (googlemaps)]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=127332#p127332</link>
			<description><![CDATA[<p>Hi,&nbsp; <br />My googlemap app allows users to add points by clicking on map and bringing up an info box with&nbsp; SAVE / DELETE options.&nbsp; On SAVE I&#039;d like to call my existing Rails action that ajax updates a div on the page with a new line with some info about the location selected. <br />&nbsp; &nbsp;<br />Problem is I can&#039;t figure out how to call the Rails action from the javascript function.&nbsp; Any advice on calling rails actions from javascript would be appreciated.&nbsp; &nbsp;</p><p>Javascript and Rails code</p><p>Javascript function to SAVE selected point:&nbsp; </p><p>function tripWaypointSave(m){<br />&nbsp; &nbsp; for (x in allmarkers)<br />&nbsp; &nbsp;&nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; if (allmarkers[x].get(&quot;MarkerID&quot;) == m)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allmarkers[x].set(&quot;DelFlag&quot;, &quot;N&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (y in allinfo)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Close the corresponding info window<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (allinfo[y].get(&quot;MarkerID&quot;) == m)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allinfo[y].set(&quot;DelFlag&quot;, &quot;N&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allinfo[y].close();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Correct info box now closed BUT HOW TO CALL THE RAILS ACTION?<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; remote_function(:url =&gt; { :action =&gt; &quot;add_to_trip&quot;} );<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp;&nbsp; &nbsp;}&nbsp; &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; marker.setMap(null);<br />&nbsp; &nbsp; waypointInfo.close();<br />}</p><p>Rails action (for test purposes this is presently just a button that uses ajax to add a new line to the page without refreshing the map).</p><p>&lt;% form_remote_tag :url =&gt; {:action =&gt; &quot;add_to_trip&quot;} do %&gt;<br />&nbsp; &nbsp; &lt;%= submit_tag &quot;Add to Trip 2&quot;%&gt;<br />&lt;% end %&gt;</p>]]></description>
			<author><![CDATA[dummy@example.com (petetodd)]]></author>
			<pubDate>Sun, 04 Jul 2010 16:26:31 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=127332#p127332</guid>
		</item>
	</channel>
</rss>
