<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Data from Javascript to Rails?</title>
	<link>http://ask.metafilter.com/57570/Data-from-Javascript-to-Rails/</link>
	<description>Comments on Ask MetaFilter post Data from Javascript to Rails?</description>
	<pubDate>Fri, 23 Feb 2007 19:01:41 -0800</pubDate>
	<lastBuildDate>Fri, 23 Feb 2007 19:01:41 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Data from Javascript to Rails?</title>
		<link>http://ask.metafilter.com/57570/Data-from-Javascript-to-Rails</link>	
		<description>How can I pass data created via javascript to my Rails application? &lt;br /&gt;&lt;br /&gt; I am working on a Rails application that relies on user input for some data that needs to store in the database. The data is created by the user clicking inside a div at various points, and the data that I need to store is the mouse coordinates where the user clicks.&lt;br&gt;
&lt;br&gt;
So, the view loads and the user clicks various places. Of course, capturing the mouse position is easily accomplished. Where I am stuck is in how to pass the array of data that I created wtih Javascript to my Rails controller for processing.&lt;br&gt;
&lt;br&gt;
Any help is greatly appreciated.</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2007:site.57570</guid>
		<pubDate>Fri, 23 Feb 2007 18:49:56 -0800</pubDate>
		<dc:creator>jxpx777</dc:creator>
		
			<category>javascript</category>
		
			<category>ruby</category>
		
			<category>rubyonrails</category>
		
	</item> <item>
		<title>By: IshmaelGraves</title>
		<link>http://ask.metafilter.com/57570/Data-from-Javascript-to-Rails#865609</link>	
		<description>&lt;a href=&quot;http://json.org/&quot;&gt;JSON&lt;/a&gt; is great for this sort of thing. Pass it in via AJAX or as a GET or POST parameter with a form submission.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57570-865609</guid>
		<pubDate>Fri, 23 Feb 2007 19:01:41 -0800</pubDate>
		<dc:creator>IshmaelGraves</dc:creator>
	</item><item>
		<title>By: cschneid</title>
		<link>http://ask.metafilter.com/57570/Data-from-Javascript-to-Rails#865649</link>	
		<description>If you want to submit the whole page, throw the data into a hidden form element, and make the submit just send in the form.  Then it&apos;s like any other.  If you need to do it asyncronously, just use ajax.  Just use the normal ajax commands in rails (remote_function looks about right) to call the controller w/ the args.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57570-865649</guid>
		<pubDate>Fri, 23 Feb 2007 20:48:24 -0800</pubDate>
		<dc:creator>cschneid</dc:creator>
	</item><item>
		<title>By: beerbajay</title>
		<link>http://ask.metafilter.com/57570/Data-from-Javascript-to-Rails#865689</link>	
		<description>Seconding what cshneid said. You use the javascript to fill in the &quot;value&quot; attribute of hidden form fields (using normal DOM functions), then submit the form at the appropriate time. Same as any other form processing.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57570-865689</guid>
		<pubDate>Fri, 23 Feb 2007 22:12:57 -0800</pubDate>
		<dc:creator>beerbajay</dc:creator>
	</item><item>
		<title>By: gaby</title>
		<link>http://ask.metafilter.com/57570/Data-from-Javascript-to-Rails#865772</link>	
		<description>Ref JSON, you may need to use POST to pass it as there&apos;s a limit on the size of a URL, and a JSON object could become quite large.  As cschneld suggested, stick it in a hidden form element and POST it into Rails.&lt;br&gt;
&lt;br&gt;
I&apos;d suggest using the ScriptAculous libraries to do this:&lt;br&gt;
&lt;br&gt;
&amp;lt;input type=&quot;hidden&quot; id=&quot;json&quot; name=&quot;json&quot; value=&quot;&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script&amp;gt;&lt;br&gt;
&lt;br&gt;
// Whatever your data object is here&lt;br&gt;
var my_data = { test: [&quot;one&quot;,&quot;two&quot;] };&lt;br&gt;
&lt;br&gt;
// Assuming JSON is a class that can encode or decode&lt;br&gt;
// json data.&lt;br&gt;
$( &quot;json&quot; ).value = JSON.encode( my_data );&lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57570-865772</guid>
		<pubDate>Sat, 24 Feb 2007 05:17:08 -0800</pubDate>
		<dc:creator>gaby</dc:creator>
	</item>
	</channel>
</rss>
